Skip to content

Instantly share code, notes, and snippets.

@abdennour
Last active May 21, 2020 04:03
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 abdennour/acfee0659a61bb156bbd6b0db112b10e to your computer and use it in GitHub Desktop.
Save abdennour/acfee0659a61bb156bbd6b0db112b10e to your computer and use it in GitHub Desktop.
Mimic Haskell with Javascript in Functional Programming and Composition
function _(...fns) {
return x => fns.reverse().reduce((reduced, f ) => f(reduced), x )
}
const sum = arr => arr.reduce((a, b) => a + b, 0 )
const filter = (fn, arr) => arr === undefined ? b => filter(fn, b) : arr.filter(fn)
// export
import 'haskell.js'
// Haskell: sum . filter(>4) [5, 6, 3]
_(sum, filter(x => x> 4))([5, 6, 3])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment