Create transfer-array method and use it (#987)

* Create transfer-array method and use it

* License headers

* Update ASArrayByFlatMapping
This commit is contained in:
Adlai Holler
2018-06-29 18:21:55 -07:00
committed by GitHub
parent a4f78ad3e0
commit 77e2d28919
15 changed files with 213 additions and 34 deletions

View File

@@ -214,13 +214,18 @@
/**
* Create a new array by mapping `collection` over `work`, ignoring nil.
*/
#define ASArrayByFlatMapping(collection, decl, work) ({ \
NSMutableArray *a = [[NSMutableArray alloc] init]; \
for (decl in collection) {\
id result = work; \
if (result != nil) { \
[a addObject:result]; \
#define ASArrayByFlatMapping(collectionArg, decl, work) ({ \
id __collection = collectionArg; \
NSArray *__result; \
if (__collection) { \
id __buf[[__collection count]]; \
NSUInteger __i = 0; \
for (decl in __collection) {\
if ((__buf[__i] = work)) { \
__i++; \
} \
} \
__result = [NSArray arrayByTransferring:__buf count:__i]; \
} \
a; \
__result; \
})