Last active
December 10, 2015 23:30
-
-
Save shesek/4510144 to your computer and use it in GitHub Desktop.
possible implementations for partial application with pre-evaluated bound arguments and function target in CoffeeScript. See https://github.com/jashkenas/coffee-script/pull/2597
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# With an helper function: | |
partial = (fn, a...) -> (b...) -> fn a..., b... | |
add_3 = partial add, 3 | |
# With an IIFE: | |
add_3 = do (fn=add, a=3) -> (b...) -> fn a, b... | |
# note: because we know the number of bound arguments at compile-time, the do() IIFE could be | |
# compiled with the exact number of arguments, rather than with a splat. | |
# the do thingy is the same as `add_3 = ( (fn, a) -> (b...) -> fn a, b... ) add, 3` | |
# Or with a bunch of temporary variables: | |
ref1 = fn | |
ref2 = 3 | |
add_3 = (b...) -> ref1 ref2, b... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment