Skip to content

Instantly share code, notes, and snippets.

@haru01
Created November 4, 2018 02:21
Show Gist options
  • Select an option

  • Save haru01/b1d90e7790cccbce8ea65dddc72e5ed1 to your computer and use it in GitHub Desktop.

Select an option

Save haru01/b1d90e7790cccbce8ea65dddc72e5ed1 to your computer and use it in GitHub Desktop.
inc = (n) => n + 1
inc(2)
square = (n) => n * n
[1,2,3].map(inc) // [ 2, 3, 4 ]
[1,2,3].map(square) // [ 1, 4, 9 ]
compose = (...fns) => x => fns.reduceRight((v, f) => f(v), x);
incSquare = compose(inc, square)
incSquare(3) // 10
pipe = (...fns) => x => fns.reduce((v, f) => f(v), x)
incAndThenSquare = pipe(inc, square)
incAndThenSquare(3) // 16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment