Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Obsolete—use https://github.com/robrix/Reducers instead.
Objective-C C Groff Other

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
RXCollections.xcodeproj
RXCollections
RXCollectionsTests
.gitignore
LICENSE
README.mdown

README.mdown

RXCollections

Folds, maps, filters, and detects for Cocoa collections (including your own), with as little chaff as possible.

In short:

#import "RXCollections.h"

…
RXMap(people, nil, ^(Pal *each) { return each.phoneNumber; });

RXFilter(ungulates, nil, ^(id<Ungulate> each) { return each.stomachCount == 4; });

RXFold(chunksOfText, @"", ^(NSString *full, NSString *each) { return [full stringByAppendingString:each]; });

RXDetect(scientists, ^(Scientist *each) { return [each.name isEqualToString:@"Richard Feynman"]; });

Collections that can be created

Maps and filters take a second argument, a collection into which to place their results. This can be a set or an array currently, and if you pass nil, RXMap and RXFilter will build a collection of the same type as the collection being mapped or filtered.

Collections that can be traversed

RXFold and RXDetect can traverse anything conforming to NSFastEnumeration (which includes, among other things, NSEnumerator and NSManagedObjectModel). RXMap and RXFilter’s extra logic for building a collection of the same type as their subject requires these collections to conform to the RXCollection protocol.

Notes

  • More documentation is available in RXCollections.h.

  • The included Xcode target compiles a static archive, but there’s no real need to use it; you can just link RXCollections.m in directly and #import "RXCollections.h". This approach may reduce the barrier to use.

  • All Objective-C objects descending from NSObject now conform to NSFastEnumeration, simply returning themselves if they do not otherwise implement it. This is to be considered experimental and likely unwise.

Future

  • Pairs, for constructing dictionaries (among other things).

  • Zip.

Something went wrong with that request. Please try again.