Open robb opened 10 years ago
Should be ok?! I'm wondering whether it would make (style-)sense to pass the initial value separately, giving all transformations the same form:
NSArray *result = ASTChain(tweets,
ASTPluck(_, @keypath(XYTweet.new, message)),
ASTFilter(_, ^(id obj) {
return [obj isKindOfClass:NSString.class];
}),
ASTMap(_, ^(NSString *string) {
return string.capitalizedString;
})
);
NSLog(@"%@", result);
That works already
This adds
ASTChain
, a helper macro to reduce boilerplate in cases where intermediate results of a transformation would pollute the current scope.E.g.
could be replaced with
removing the need for temporary
messages
andstrings
variables.I think it's worth pointing out that the
_
variable contains the result and has the type of the previous expression. In the above example, this makes sure that the correctASTMap
version is picked (in this case the one for arrays).Would love to hear some opinions on this, since it may just be a little to much macro-magic…