Archive for January 15, 2009

Thursday, January 15, 2009

NSArray+Functional

Nicolas Seriot has written a category on NSArray to add map, filter, and reduce functionality. You pass a selector and a variable number of arguments, and it performs the selector on each object in the array. Blocks are much nicer, of course, but they’re not available yet in Objective-C. Higher order messaging provides type-checking at compile time and supports more types of arguments, however the va_arg approach is simpler than HOM and works better with selectors that return BOOL.