Re: Filter an array
Re: Filter an array
- Subject: Re: Filter an array
- From: Jens Alfke <email@hidden>
- Date: Thu, 28 Jul 2011 16:21:23 -0700
On Jul 28, 2011, at 1:35 PM, Chris Paveglio wrote:
> I'm looking at using: - (NSArray *)filteredArrayUsingPredicate:(NSPredicate *)predicate
I was going to suggest using a block to filter, but it seems that Foundation collections still don’t implement the standard functional operators like ‘map’ and ‘filter' found in lots of other languages. Which is too bad, since otherwise you could write it compactly as
NSArray* filtered = [paths filter: ^(NSString path){
return [validExtensions containsObject: path.pathExtension.lowercaseString];
}];
There’s -indexesOfObjectsWithOptions:passingTest:, as Kyle pointed out, but that adds another step of generating and using an index-set.
I found the lack of -map so annoying that I wrote a category method for it in my current project...
—Jens
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden