robb / Underscore.m

A DSL for Data Manipulation
https://robb.github.io/Underscore.m/
MIT License
1.47k stars 99 forks source link

Why wrappers are required? #40

Closed yuanmai closed 11 years ago

yuanmai commented 11 years ago

Any reason to prefer wrapper over Category? Using category, we can achieve:

@[a, b, c].map(^(NSString *string) {
    return string.capitalizedString;
})

without any wrapping, right?

robb commented 11 years ago

whoops, hit reply too early

robb commented 11 years ago

Yes, but categories should be prefixed, so you'd have

@[a, b, c].us_map(^(NSString *string) {
    return string.capitalizedString;
});

which I don't find very pleasing, aesthetically. If prefer that, which I totally understand, check out BlocksKit, it uses categories and supports a similar functionality.

That being said, I have a branch where the wrappers are NSProxies, allowing you to skip the unwrapping, like so:

NSArray *myArray = _.wrap(@[foo])
   .map(^(NSString *string) {
        return string.capitalizedString;
    })
    .filter(^(NSString *foo){
        // yadda yadda
    });

Note that for the non-chaining use case you can already use

_.arrayMap(@[a, b, c], ^(NSString *string) {
    return string.capitalizedString;
});
yuanmai commented 11 years ago

Thanks for your explanation.