Skip to content

Instantly share code, notes, and snippets.

View santiago-su's full-sized avatar

Santiago Suárez santiago-su

View GitHub Profile
@Avaq
Avaq / fold.js
Last active March 5, 2018 12:28
Functional JavaScript cookbook
//Combinators
const I = x => x;
//List manipulation
const head = xs => xs[0];
const tail = xs => xs.slice(1);
const append = x => xs => [...xs, x];
//Iteration
const foldl = f => y => xs => xs.length > 0 ? foldl(f)(f(y)(head(xs)))(tail(xs)) : y;