Skip to content

Instantly share code, notes, and snippets.

@dinocarl
Last active October 14, 2022 14:59
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 dinocarl/de4e3e52e2f03783831a29957a2cb5e4 to your computer and use it in GitHub Desktop.
Save dinocarl/de4e3e52e2f03783831a29957a2cb5e4 to your computer and use it in GitHub Desktop.
A dot operator function with reduce
const dot = (f, g) => a => f(g(a));
const cmp = reduce(dot, identity);
const cmp2 = reduce(o, identity);
[
compose(
sum,
range(2),
inc,
multiply(4)
)(1),
cmp([
sum,
range(2),
inc,
multiply(4)
])(1),
cmp2([
sum,
range(2),
inc,
multiply(4)
])(1),
dot(dot(dot(sum, range(2)), inc), multiply(4))(1),
o(o(o(sum, range(2)), inc), multiply(4))(1),
sum(range(2)(inc(multiply(4)(1)))),
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment