A DSL for Data Manipulation

Related tags

Utility Underscore.m
Overview

Underscore.m

About Underscore.m

Underscore.m is a small utility library to facilitate working with common data structures in Objective-C.
It tries to encourage chaining by eschewing the square bracket]]]]]].
It is inspired by the awesome underscore.js.

Real world example

// First, let's compose a twitter search request
NSURL *twitterSearch = [NSURL URLWithString:@"http://search.twitter.com/search.json?[email protected]&rpp=100"];

// ... then we fetch us some json ...
NSData *data = [NSData dataWithContentsOfURL:twitterSearch];

// ... and parse it.
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data
                                                     options:kNilOptions
                                                       error:NULL];

// This is where the fun starts!
NSArray *tweets = [json valueForKey:@"results"];

NSArray *processed = _array(tweets)
    // Let's make sure that we only operate on NSDictionaries, you never
    // know with these APIs ;-)
    .filter(Underscore.isDictionary)
    // Remove all tweets that are in English
    .reject(^BOOL (NSDictionary *tweet) {
        return [[tweet valueForKey:@"iso_language_code"] isEqualToString:@"en"];
    })
    // Create a simple string representation for every tweet
    .map(^NSString *(NSDictionary *tweet) {
        NSString *name = [tweet valueForKey:@"from_user_name"];
        NSString *text = [tweet valueForKey:@"text"];

        return [NSString stringWithFormat:@"%@: %@", name, text];
    })
    .unwrap;

Documentation

Documentation for Underscore.m can be found on the website.

Issues
  • Wrapped library with familiar _.function convention.

    Wrapped library with familiar _.function convention.

    Hi Robert,

    Yesterday, I went looking for an objective-C implementation of underscore and found yours! I have very impressed with the amazing property trick for implementing .functionName syntax.

    However, felt the syntax and forced chaining could a little unconventional in the sense that I believe an Underscore.js user would just want something identical as much as possible. So I wrapped your library using the _.function convention, I introduced a convention of _.functionNameC for the library user to choose Chaining, and I added _,indexOf and _.defer because I was using them in my own library.

    A few thoughts:

    1. As an optimization, I copied some common code to the _.functionName implementation. Obviously having duplicate code is not great, but I wanted to avoid unnecessary collection copying through the Wrappers. Maybe someone in the community can review this for more optimizations (maybe some implementations belong in the Wrappers and some in the _.functionName).

    2. I was originally trying to store _ in an extern rather than as a singleton, but couldn't get it to work. If you have any ideas to do that to avoid the extra [Underscore sharedInstance] calls, please do!

    3. I ended up removing some of your '- (id)init __deprecated;' for the singleton to create an instance. Hopefully that is the best approach.

    I hope you accept this pull request!

    Kevin

    opened by kmalakoff 20
  • Add a `perform` method

    Add a `perform` method

    Add a perform method similar to underscore.js' invoke method that performs a selector on every object in the array/dictionary.

    enhancement wontfix 
    opened by robb 14
  • Add support for NSString?

    Add support for NSString?

    Just thinking out loud here

    Underscore.string(@"It was the best of times, it was the worst of times")
         .downcase
         .strip(@[ @"," ]) 
         .split(@" ")
         .uniq // Array
         .join(@", ")
         .unwrap; // @"it, was, the, best, of, times, worst"
    

    Suppose there was apply for dictionaries

    Underscore.dict(data)
        .filterKeys(Underscore.isKeyPath(target))
        .defaults(kDefaultValues)
        .apply(target)
    
    question 
    opened by robb 10
  • [WIP] String support

    [WIP] String support

    This will eventually add basic string support to Underscore.m

    • [x] trim
    • [ ] capitalize
    • [ ] lowercase
    • [ ] uppercase
    • [ ] split
    • [ ] join

    Fixes #22

    opened by robb 9
  • Release preparation

    Release preparation

    I've done a bit of a tidy. Fixed a failing test and updated the pod spec. Let me know if there's anything else that needs too e done. I'd like to merge soon and then update master shortly thereafter and get cocoa pod updated.

    I also updated the pods and project settings to work with the latest Xcode.

    @robb Do you think it's worth adding Carthage support?

    enhancement 
    opened by khendry 9
  • Add group_by method for arrays

    Add group_by method for arrays

    Say I have this array of dictionaries:

    NSArray *names = @[ @{"name" : @"john", "sex" : "male"}, @{"name" : @"alice", "sex" : "female"}, @{"name" : @"mary", "sex" : "female"}];
    

    The command names.group_by(@"sex") will return the array grouped by the sex.

    @[ @[@{"name" : @"john", "sex" : "male"}], @[@{"name" : @"alice", "sex" : "female"}, @{"name" : @"mary", "sex" : "female"}]];
    

    I think this may be possible to do right now by chaining, but would be good to have this added to the main methods in Underscore+Functional.h

    duplicate 
    opened by esusatyo 8
  • Added isEmpty method

    Added isEmpty method

    Based on my macro code from here: https://gist.github.com/iandrewfuchs/5520045

    Let me know what you think. Cheers!

    opened by churchofthought 6
  • Add sorting abilities for NSArray

    Add sorting abilities for NSArray

    enhancement 
    opened by amiel 5
  • Where to import and alias?

    Where to import and alias?

    Hi Robert,

    Love the library, as I love underscore.js. Got it working with the CocoaPods installation.

    But I gotta ask, how do you install Underscore.m globally with the alias? ie. where do I put:

    #import "Underscore.h"
    #define Underscore _
    

    I tried -Prefix.pch, which worked in 0.1.0. It doesn't seem to work now. Instead, I get: Pods/Headers/Underscore.m/Underscore.h:34:3: Underscore.m requires Automatic Reference Counting to be enabled

    Thanks!

    opened by s12chung 5
  • Add times method

    Add times method

    I like this useful method! http://underscorejs.org/#times Please review @robb .

    opened by akitsukada 5
  •  Memory Error fix

    Memory Error fix

    nil passed to a callee that requires a non-null 1st parameter

    bug 
    opened by justvanbloom 3
  • Carthage support

    Carthage support

    Is there any plan for Carthage support?

    question 
    opened by williamsjj 1
  • Add support to tvos via cocoapods

    Add support to tvos via cocoapods

    Underscore.m (0.2.1), which does not support tvos.

    enhancement 
    opened by cm-hugog 0
  • Add difference method

    Add difference method

    enhancement 
    opened by nicolasmuller 0
  • Added method to ZIP multiple arrays

    Added method to ZIP multiple arrays

    Added method to zip elements passing an array of arrays that returns another array of arrays zipped. This method only works if all the sub-arrays have the same length (should i add some checks here?)

    this:

    @[@[@1, @2, @3], @[@4, @5, @6], @[@7, @8, @9]]
    

    transforms into this:

    @[@[@1, @4, @7], @[@2, @5, @9], @[@3, @6, @9]]
    

    :warning: all the arrays should have the same lenght

    I would like to add specs, but can't make the tests run. Always getting this error after pod install:

    ld: library not found for -lPods-UnderscoreTests-Expecta
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    
    enhancement 
    opened by isaacroldan 2
  • Website : Typo

    Website : Typo

    The documentation for find says:

    Returns an object from the array **the** passes the test 
    

    It should say "array that passes the test"

    opened by jasperblues 0
  • _.union

    _.union

    _.union is not in Underscore.m, but would be useful.

    enhancement 
    opened by JoshOldenburg 1
  • Add functions from underscore-contrib?

    Add functions from underscore-contrib?

    There are some very useful functions in underscore-contrib that are missing from underscore.js: http://documentcloud.github.io/underscore-contrib/

    My plan is to fork Underscore.m and add these methods as I need them, but I wanted to check that you are open to adding functions like these first. Thanks!

    opened by ninjudd 4
  • Added max & min method

    Added max & min method

    opened by avalanched 1
  • Inline Documentation

    Inline Documentation

    http://cocoadocs.org/docsets/Underscore.m/0.2.1/Classes/USArrayWrapper.html

    It'd be cool to have some inline documentation for both Xcode & CocoaDocs :beer:

    enhancement 
    opened by orta 7
Owner
Robert Böhnke
It's dangerous to go alone,​ take this: 🖤
Robert Böhnke
A tiny generator of random data for swift

SwiftRandom SwiftRandom is a tiny help suite for generating random data such as Random human stuff like: names, gender, titles, tags, conversations Ra

Kan Yilmaz 558 Nov 23, 2021
Random data generation in Swift

RandomKit is a Swift framework that makes random data generation simple and easy. Build Status Installation Compatibility Swift Package Manager CocoaP

Nikolai Vazquez 1.5k Nov 20, 2021
Functional data types and functions for any project

Swiftx Swiftx is a Swift library containing functional abstractions and extensions to the Swift Standard Library. Swiftx is a smaller and simpler way

TypeLift 221 Nov 23, 2021
A Swift DSL that allows concise and effective concurrency manipulation

NOTE Brisk is being mothballed due to general incompatibilities with modern version of Swift. I recommend checking out ReactiveSwift, which solves man

Jason Fieldman 25 May 24, 2019
Advanced color manipulation for iOS.

ColorKit ColorKit is your companion to work with colors on iOS. Features Installation Sample Project Contributing License Features Dominant Colors Col

Boris Emorine 429 Nov 19, 2021
A time and calendar manipulation library for iOS 9+, macOS 10.11+, tvOS 9+, watchOS 2+ written in Swift 4.

SwiftMoment This framework is inspired by Moment.js. Its objectives are the following: Simplify the manipulation and readability of date and interval

Adrian Kosmaczewski 1.6k Nov 23, 2021
Streaming and realtime audio manipulation with AVAudioEngine

SwiftAudioPlayer Swift-based audio player with AVAudioEngine as its base. Allows for: streaming online audio, playing local file, changing audio speed

null 290 Nov 29, 2021
A DSL to make animation easy on iOS with Swift.

This project is highly inspired by JHChainableAnimations, If you project is developed with Objective-C, use JHChainableAnimations instead. With DKChai

Draven 1.9k Nov 18, 2021
An NSPredicate DSL for iOS, OSX, tvOS, & watchOS. Inspired by SnapKit and lovingly written in Swift.

PrediKit A Swift NSPredicate DSL for iOS & OS X inspired by SnapKit, lovingly written in Swift, and created by that weird dude at KrakenDev. If you're

Hector Matos 543 Nov 17, 2021
A Swift Autolayout DSL for iOS & OS X

SnapKit is a DSL to make Auto Layout easy on both iOS and OS X. ⚠️ To use with Swift 4.x please ensure you are using >= 4.0.0 ⚠️ ⚠️ To use with Swift

null 18k Nov 21, 2021
A declarative Auto Layout DSL for Swift :iphone::triangular_ruler:

Cartography ?? ?? Using Cartography, you can set up your Auto Layout constraints in declarative code and without any stringly typing! In short, it all

Robert Böhnke 7.3k Nov 27, 2021
MisterFusion is Swift DSL for AutoLayout. It is the extremely clear, but concise syntax, in addition, can be used in both Swift and Objective-C. Support Safe Area and Size Class.

MisterFusion MisterFusion makes more easier to use AutoLayout in Swift & Objective-C code. Features Simple And Concise Syntax Use in Swift and Objecti

Taiki Suzuki 318 Nov 7, 2021
Tiny Swift DSL for Autolayout

SwiftAutoLayout SwiftAutoLayout is a tiny DSL for Autolayout intended to provide a more declarative way to express layout constraints. Here's a quick

Indragie Karunaratne 659 Nov 23, 2021
Yet Another Swift Auto Layout DSL

FormationLayout Documentation FormationLayout is the top level layout class for one root view. FormationLayout takes a UIView as its rootView. transla

Evan Liu 53 Jun 3, 2021
Bank Card Generator with Swift using SnapKit DSL 💳

iCard BankCard & CreditCard generator with Swift 3 using SnapKit DSL iCard is a simple tool for generate Credit & Bank Card , it represent cards as UI

Emrah Korkmaz 328 Oct 28, 2021
Sinatra-like DSL for developing web apps in Swift

Swiftra Swiftra is a library that provides DSLs like Sinatra. System Requirements DEVELOPMENT-SNAPSHOT-2016-02-08-a Example See swiftra-example. impor

Shun Takebayashi 267 Jun 10, 2021
Frank is a DSL for quickly writing web applications in Swift

Frank Frank is a DSL for quickly writing web applications in Swift with type-safe path routing. Sources/main.swift import Frank // Handle GET request

Kyle Fuller Archive 380 Jul 25, 2021
An Impressive Auto Layout DSL for iOS, tvOS & OSX. & It is written in pure swift.

KVConstraintKit KVConstraintKit is a DSL to make easy & impressive Auto Layout constraints on iOS, tvOS & OSX with Swift Installation Using CocoaPods

Keshav Vishwkarma 91 Nov 9, 2021
A compact but full-featured Auto Layout DSL for Swift

Mortar allows you to create Auto Layout constraints using concise, simple code statements. Use this: view1.m_right |=| view2.m_left - 12.0 Instead of:

Jason Fieldman 82 Dec 7, 2020
An NSPredicate DSL for iOS, OSX, tvOS, & watchOS. Inspired by SnapKit and lovingly written in Swift.

PrediKit A Swift NSPredicate DSL for iOS & OS X inspired by SnapKit, lovingly written in Swift, and created by that weird dude at KrakenDev. If you're

Hector Matos 543 Nov 17, 2021
Bank Card Generator with Swift using SnapKit DSL 💳

iCard BankCard & CreditCard generator with Swift 3 using SnapKit DSL iCard is a simple tool for generate Credit & Bank Card , it represent cards as UI

Emrah Korkmaz 328 Oct 28, 2021
JSON to Core Data and back. Swift Core Data Sync.

Notice: Sync was supported from it's creation back in 2014 until March 2021 Moving forward I won't be able to support this project since I'm no longer

Nes 2.5k Nov 17, 2021
A minimalistic, thread safe, non-boilerplate and super easy to use version of Active Record on Core Data. Simply all you need for doing Core Data. Swift flavour.

Skopelos A minimalistic, thread-safe, non-boilerplate and super easy to use version of Active Record on Core Data. Simply all you need for doing Core

Alberto De Bortoli 234 Nov 17, 2021
💾🔍🧮 BinaryKit helps you to break down binary data into bits and bytes, easily access specific parts and write data to binary.

BinaryKit BinaryKit helps you to break down binary data into bits and bytes, easily access specific parts and write data to binary. Access Bytes By us

Devran Cosmo Uenal 101 Nov 21, 2021
Magical Data Modeling Framework for JSON - allows rapid creation of smart data models. You can use it in your iOS, macOS, watchOS and tvOS apps.

JSONModel - Magical Data Modeling Framework for JSON JSONModel allows rapid creation of smart data models. You can use it in your iOS, macOS, watchOS

JSONModel 6.8k Nov 18, 2021
Easy to use cryptographic framework for data protection: secure messaging with forward secrecy and secure data storage. Has unified APIs across 14 platforms.

Themis provides strong, usable cryptography for busy people General purpose cryptographic library for storage and messaging for iOS (Swift, Obj-C), An

Cossack Labs 1.4k Nov 25, 2021
Easy to use cryptographic framework for data protection: secure messaging with forward secrecy and secure data storage. Has unified APIs across 14 platforms.

Themis provides strong, usable cryptography for busy people General purpose cryptographic library for storage and messaging for iOS (Swift, Obj-C), An

Cossack Labs 1.4k Nov 25, 2021
Magical Data Modeling Framework for JSON - allows rapid creation of smart data models. You can use it in your iOS, macOS, watchOS and tvOS apps.

JSONModel - Magical Data Modeling Framework for JSON JSONModel allows rapid creation of smart data models. You can use it in your iOS, macOS, watchOS

JSONModel 6.8k Aug 23, 2021
A library for converting Adobe AE shape based animations to a data format and playing it back on Android and iOS devices.

Keyframes Keyframes is a combination of (1) an ExtendScript script that extracts image animation data from an After Effects file and (2) a correspondi

Facebook Archive 5.4k Nov 24, 2021