Skip to content

Instantly share code, notes, and snippets.

@dewey92
Last active July 4, 2017 09:22
Show Gist options
  • Select an option

  • Save dewey92/eeebd2a88359cc88fe3c644a84a826a1 to your computer and use it in GitHub Desktop.

Select an option

Save dewey92/eeebd2a88359cc88fe3c644a84a826a1 to your computer and use it in GitHub Desktop.
// composeK :: Monad m => ((y → m z), (x → m y), …, (a → m b)) → (a → m z)
const composeK = (...fns) => init => {
if (!fns.length) throw new Error('Need at least 1 argument')
const lastArg = fns.pop();
return fns.reduceRight((acc, x) => acc.bind(x), lastArg(init))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment