Skip to content

Instantly share code, notes, and snippets.

@mikeabdullah
Forked from boredzo/PRHArrayByMap.h
Created February 12, 2014 14:39
Show Gist options
  • Save mikeabdullah/8956676 to your computer and use it in GitHub Desktop.
Save mikeabdullah/8956676 to your computer and use it in GitHub Desktop.
extern NSArray *PRHArrayByMap(NSArray *inArray, id (^block)(id));
NSArray *PRHArrayByMap(NSArray *inArray, id (^block)(id)) {
if (inArray == nil)
return nil;
NSCParameterAssert(block != nil);
NSMutableArray *outArray = [NSMutableArray arrayWithCapacity:inArray.count];
for (id obj in inArray) {
id result = block(obj);
NSCAssert(result != nil, @"%s: block(%@) returned nil—array follows\n%@", __func__, obj, inArray);
[outArray addObject:result];
}
return outArray;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment