Saturday, February 16, 2013

RXCollections

Rob Rix’s RXCollections offers:

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

The interesting part is that:

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.

And they can work with custom collection types that conform to the proper protocol.

4 Comments RSS · Twitter

Mike Ash's MACollectionUtilities are still the holy grail for Cocoa Collection methods aka. Higher Order Functions. Clever use of preprocessor macros get the arkward block syntax out of your way, so the code is much easier to read.

Thanks for the shout out!

I’m actually a little bit embarrassed about the “interesting” part there, as it conflates folds and maps. My current effort is to build lazy maps and collection constructors such that it doesn’t have to fold internally (which is inflexible and leads to semantic weirdness like the RXCollection protocol and its implementation in categories on All The Things).

So:

RXConstructSet(RXLazyMap(@[…], ^(id each){ return …; }))

This also makes it more obvious how to construct a dictionary from some enumeration—once I have implemented RXConstructDictionary!—since you only have to produce pairs.

In fact, I want to replace the non-lazy maps, filters, etc with lazy ones. I’m not eager to break backwards-compatibility, but I think mistakes should be corrected (and there are tags for older releases).

Anyway, thanks again!

@Ilja: I was thinking this morning that a simple RXWithEach macro might be nice:

#define RXWithEach(x) ^id(id each){ return (x); }

That said, I seem to mind block syntax rather less than most of my peers!

[...] It’s interesting to compare this with RXCollections. [...]

Leave a Comment