by mpweiher · 12y ago · 0 comments
#( 1 2 3 4 5 ) collect + 5
This also works with HOM, as does -ifResponds, -async etc.+ arg ^self collect: [:each | each + arg]
[[@[@1, @2, @3] valueForKeyPath:@"@sum.self"] integerValue] + 5
This can be improved: @implementation NSArray (Private)
- (NSInteger)collect {
return [[self valueForKeyPath:@"@sum.self"] integerValue];
}
@end
And then you can write: [[@[@1, @2, @3] collect] + 5;
I know: HOM is a more abstract/generic thing. If it was built in the language you could just use it as is without reinventing the wheel all the time... I just want to point out that Objective-C can be made look nice as well :)However, collect + 5 doesn't first sum and then add 5 to the sum, it distributes the +5 to every element, and any other message you care to send.
How can I do you something good? Beer? Candy? :) Back in the days I read your paper and obviously I forgot what "collect" means...
If you are Marcel then you are one of my heros.