Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

What's the advantage of implementing map/filter as property accessors of a wrapper object instead of just doing:

    NSArray* map(id<NSFastEnumeration> enumerable, id(^)(id object) block);
?

Obviously, you'd still want to have a prefix of some sort for namespacing.



In the case of NSDictionary, Underscore.m's map iterates over objects and keys. Fast Enumeration only iterates over the dictionary's keys, when you probably want the value or both.

But I agree, supporting any class that implements NSFastEnumeration would be nice to have.


You may already know this, but you can also enumerate over NSDictionary entries using enumerateKeysAndObjectsUsingBlock: [1] and enumerateKeysAndObjectsWithOptions:usingBlock: [2].

The latter giving you the ability to enumerate in reverse order or spread the enumeration across multiple cores using Grand Central Dispatch.

[1] https://developer.apple.com/library/mac/documentation/Cocoa/...: [2] https://developer.apple.com/library/mac/documentation/Cocoa/...:


It's exactly what's used internally :)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: