Skip to content

Instantly share code, notes, and snippets.

@afuggini
Last active June 12, 2020 00:21
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 afuggini/2eca1b6c328fa2501b3755de39900e22 to your computer and use it in GitHub Desktop.
Save afuggini/2eca1b6c328fa2501b3755de39900e22 to your computer and use it in GitHub Desktop.
Functional Helpers (In ES6 Syntax)
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