robb / Asterism

Asterism is yet another functional toolbelt for Objective-C. It tries to be typesafe and simple.
http://robb.github.io/Asterism/
MIT License
226 stars 12 forks source link

ASTCompose #1

Closed felixvisee closed 11 years ago

felixvisee commented 11 years ago

ASTCompose adds function composition to Asterism. Short example:

ASTCompose(
    ASTLift0(length),
    ASTPartialRight(ASTLift(objectForKey:), @"foo")
)(@{ @"foo": @"bar" }) // == @3
felixvisee commented 11 years ago

ASTCompose clones most of the macros created for and used by ASTPartial, maybe they should be extracted?

robb commented 11 years ago

ASTCompose clones most of the macros created for and used by ASTPartial, maybe they should be extracted?

I wonder if that wouldn't make things worse. C macro metaprogramming isn't the nicest thing on earth, I'd say we leave it for now

robb commented 11 years ago

Going back and forth one this one. I'm not sure I'm convinced that

id (^block)(id) = ASTCompose(
    ASTLift0(length),
    ASTPartialRight(ASTLift(objectForKey:), @"foo")
);

beats

id (^block)(id) = ^(id arg) {
     @([[arg objectForKey:@"foo"] length]);
}

I think lift and partial are most useful when using each, map or reduce. However, if you need to invoke multiple methods, writing them out may be the clearer alternative. This feels like you lose more type information and clarity than what you lose in terms of convenience.

Also, this currently only handles id -> id? so we'd still need to add some more macros to support blocks of higher arity.