3 ms·
I am not saying that named arguments are a bad idea, in fact they are awesome! Often, they make code a lot more readable, consider for example [UIMelon mel
by robert-boehnke 14y ago
I am not saying that named arguments are a bad idea, in fact they are awesome!
Often, they make code a lot more readable, consider for example
[UIMelon melonWithNumberOfSeeds:10
andPriceInDollars:10];
which is a lot more self explanatory than
new Melon(10, 10)
That being said, for a lot of common and well known fuctions (including map, filter,
reduce), Objective-C tends to be overly verbose. I think everybody is looking forward
to the new literals, that will allow you to replace
[NSDictionary dictionaryWithObjectsAndKeys:foo, @"foo",
bar, @"bar",
nil];
with the much more concise
@{@"foo": foo, @"bar": bar}
Underscore.m tries to achieve something similar. I hope that people will be able
see past the - granted, inconventional - syntax to focus on the actual operations
done on the data structures.
For example:
// - (NSDictionary *)transformedDictionary;
NSMutableDictionary *result = [NSMutableDictionary dictionary];
[myDict enumerateKeysAndObjectsUsingBlock:^(id key, id obj) {
[result setValue:[obj transformedObject]
forKey:key];
}];
return result;
vs.
return _dict(myDict).map(^id (id key, id obj) {
return [obj transformedObject];
})
.unwrap;