Created
October 14, 2012 13:28
-
-
Save jbilcke/3888592 to your computer and use it in GitHub Desktop.
chain coffeescript functions like this -> "a b c d e" (yep, no parenthesis or ->)
This file contains 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
#!/usr/bin/env coffee | |
########### | |
# old way # | |
########### | |
# functions | |
a = (x) -> (g) -> g x * x | |
b = (x) -> (g) -> g x + x | |
c = (x) -> (g) -> g x * 100 | |
# create the future | |
f = a 42 | |
# pipeline it | |
f(b)(c)((x) -> console.log "result: #{x}") | |
# will print: 352800 | |
############ | |
# swag way # | |
############ | |
a = (x) -> (g) -> g x ; console.log "#{x}" | |
b = (g) -> (x) -> g x * x ; console.log "#{x} * #{x}" | |
c = (g) -> (x) -> g x + x ; console.log "#{x} + #{x}" | |
d = (g) -> (x) -> g x * 100 ; console.log "#{x} + 100" | |
e = (g) -> (x) -> g() ; console.log "end" | |
# does nothing | |
e b c d e | |
# process, but show nothing | |
a(42) b c d e | |
# process and show | |
a(42) b c d (x) -> console.log "result: #{x}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment