Last active
June 12, 2020 00:21
-
-
Save afuggini/2eca1b6c328fa2501b3755de39900e22 to your computer and use it in GitHub Desktop.
Functional Helpers (In ES6 Syntax)
This file contains hidden or 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
const map = f => step => (a, c) => step(a, f(c)); | |
const filter = predicate => step => (a, c) => predicate(c) ? step(a, c) : a; | |
const compose = (...fns) => x => fns.reduceRight((y, f) => f(y), x); | |
const curry = (f, arr = []) => (...args) => ( | |
a => a.length === f.length ? f(...a) : curry(f, a) | |
)([...arr, ...args]); | |
const transduce = curry((step, initial, xform, foldable) => | |
foldable.reduce(xform(step), initial) | |
); | |
const concatArray = (a, c) => a.concat([c]); | |
const toArray = transduce(concatArray, []); | |
const logStep = v => { console.log(v); return v; } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment