Categories for Foundation collection classes.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
gh-unit @ 3cbaebe


Objective-C categories for functional data structure traversal with blocks. The interface was inspired by Javascript Array Iteration Methods. The implementation was inspired by Mike Ash's Implementating Fast Enumeration Friday Q&A.


This project uses git submodules Run immediately after cloning: git submodule update --init


Your loop bodies and if predicates become reusable blocks, fine-grained code reuse points with which you can assemble larger systems.

Simple Examples

Instead of iterating your array with a for loop, you can enumerate your array. Instead of totalling your array with a for loop, you can reduce your array to a total.


Most methods return chainable NSEnumerators, so you can map, then add filtering, then add breaking, and still use a fast enumeration for loop (of course, you could always just reduce or enumerate it). (A more complex example). Arrays, sets, and enumerators use the same API, [so your blocks can interoperate, unlike foundation block enumeration)][share-blocks].


Although you can easily reduce an array to a dictionary, there is a convenience method to do it for you. Foundation APIs allow you to convert an enumerator to an array, but HBCollections gives you convenience methods to convert to a mutable array, set, and mutable set.


There is a protocol in case you have your own data structure you want to traverse. Under the hood, everything uses fast enumeration and uses just one memory buffer for intermediate storage.


BSD 3-Clause