ObjectiveSugar icon indicating copy to clipboard operation
ObjectiveSugar copied to clipboard

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

Open marcpalmer opened this issue 12 years ago • 5 comments

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 avatar Feb 06 '14 11:02 marcpalmer

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.

marcpalmer avatar Feb 06 '14 11:02 marcpalmer

Isn't that -select ?

supermarin avatar Feb 06 '14 16:02 supermarin

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

marcpalmer avatar Feb 11 '14 22:02 marcpalmer

Is this functionality already in there ?

subramanianv avatar Feb 14 '14 20:02 subramanianv

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

supermarin avatar Mar 28 '14 03:03 supermarin