Obsolete—use https://github.com/robrix/Reducers instead.
Objective-C C Other Other
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
External/Lagrangian
RXCollections.xcodeproj
RXCollections
.gitignore
LICENSE
README.mdown

README.mdown

Obsolete!

This is obsolete and unmaintained. Don’t use it! Use Reducers or ReactiveCocoa or Swift instead.

RXCollections

Lazily-evaluated (when feasible) higher-order functions for Cocoa collections (including your own), with as little chaff as possible.

In short:

#import <RXCollections/RXCollections.h>

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

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

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

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

RXConvolveWith(@[names, addresses, phoneNumbers], ^(NSUInteger count, id const objects[count]) {
	return [BusinessCard withName:objects[0] address:objects[1] phoneNumber:objects[2]];
});

(Yeah, yeah, you can call it RXZipWith instead if you like that so much better.)

Collections that can be created

Maps and filters return enumerations, which can be made into concrete collections with the RXConstruct… functions, e.g. RXConstructArray(RXMap(…)). It doesn’t matter what you’re mapping or filtering if you’re constructing a set or array; constructing dictionaries, however, requires the enumeration to produce RXKeyValuePair-conformant objects so that it can associate the keys and values it inserts.

Collections that can be traversed

RXMap, RXFold, RXFilter, RXLinearSearch can traverse anything conforming to NSFastEnumeration (which includes, among other things, NSEnumerator and NSManagedObjectModel). The returned object can itself be enumerated, as well as composed with other traversals safely and cleanly.

Notes

  • Maps, filters, and convolutions are lazily evaluated. RXConstructArray lazily constructs an array from its source enumeration.

  • More documentation is available in the header files.

  • The included Xcode target compiles a framework and a dylib, but you can also just link the source files in.

Future

  • Depth-first tree traversals with prefix/infix/postfix ordering. As a corollary, removing RXRecursiveEnumerator.

  • Concatenation of traversals.

  • Combined RXConstruct… and RXMap/RXFilter shorthands, e.g. RXMapToArray()?