Skip to content

Instantly share code, notes, and snippets.

@monorkin
Created December 23, 2018 21:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save monorkin/b8fe4c86e74707a5b73889b81ea58123 to your computer and use it in GitHub Desktop.
Save monorkin/b8fe4c86e74707a5b73889b81ea58123 to your computer and use it in GitHub Desktop.
f = -> x { x + 2 }
g = -> x { x * 2 }
# h is the composition of g and f
h = f << g
# h is the same as -> x { (x * 2) + 2 }
[1, 2, 3].map(&h) # => [4, 6, 8]
# This is exactly the same as
[1, 2, 3].map(&g).map(&f) # => [4, 6, 8]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment