supermarin / ObjectiveSugar

ObjectiveC additions for humans. Ruby style.
MIT License
2.17k stars 190 forks source link

RFE: add "all" / "every" method to collections #68

Open marcpalmer opened 10 years ago

marcpalmer commented 10 years ago

I miss this simple addition:

 - (BOOL)all:(BOOL (^)(id object))condition;

i.e:

NSArray *list = @['a', 'b', 'c'];
BOOL allMatch = [list all:^(id object) { return id != nil }];
assert( allMatch );
marcpalmer commented 10 years ago

Sorry, ditto "any" which returns YES if any one of the elements matches the condition, and returns eagerly as soon as the first match is found.

supermarin commented 10 years ago

Isn't that -select ?

marcpalmer commented 10 years ago

No, it's detect with BOOL result. Detect works but this is nice counterpart to every :)

subramanianv commented 10 years ago

Is this functionality already in there ?

supermarin commented 10 years ago

there's a PR #69, so closing this one