Skip to content

Instantly share code, notes, and snippets.

@jbilcke
Created October 14, 2012 13:28
Show Gist options
  • Save jbilcke/3888592 to your computer and use it in GitHub Desktop.
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 ->)
#!/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