Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/robb/Underscore.m
A DSL for Data Manipulation
https://github.com/robb/Underscore.m
Last synced: 3 months ago
JSON representation
A DSL for Data Manipulation
- Host: GitHub
- URL: https://github.com/robb/Underscore.m
- Owner: robb
- License: mit
- Archived: true
- Created: 2012-04-29T20:01:23.000Z (over 12 years ago)
- Default Branch: development
- Last Pushed: 2017-11-11T11:00:30.000Z (almost 7 years ago)
- Last Synced: 2024-05-17T05:43:05.939Z (6 months ago)
- Language: Objective-C
- Homepage: https://robb.github.io/Underscore.m/
- Size: 400 KB
- Stars: 1,467
- Watchers: 49
- Forks: 105
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-ios - Underscore.m - A DSL for Data Manipulation. (Utility / Web View)
- awesome-ios-star - Underscore.m - A DSL for Data Manipulation. (Utility / Web View)
README
# 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][js].[js]: http://documentcloud.github.com/underscore
## Real world example
```objective-c
// First, let's compose a twitter search request
NSURL *twitterSearch = [NSURL URLWithString:@"http://search.twitter.com/search.json?q=@SoundCloud&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](https://robb.github.io/Underscore.m/).