Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
higher-order lazy evaluation for Cocoa
Objective-C C

Bump the version.

Hopefully this should get it building with Carthage.
latest commit deae5ecfc1
Rob Rix authored

README.mdown

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()?

Something went wrong with that request. Please try again.