Last active
May 21, 2020 04:03
-
-
Save abdennour/acfee0659a61bb156bbd6b0db112b10e to your computer and use it in GitHub Desktop.
Mimic Haskell with Javascript in Functional Programming and Composition
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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