Skip to content

Instantly share code, notes, and snippets.

@slikts
Created March 11, 2018 09:24
Show Gist options
  • Save slikts/07c826d9dd8c25628dd4d31f517bc5e7 to your computer and use it in GitHub Desktop.
Save slikts/07c826d9dd8c25628dd4d31f517bc5e7 to your computer and use it in GitHub Desktop.
const compose = (f, g) => a => f(g(a));
const takeUntil = (f, xs) => xs.slice(0, xs.findIndex(f));
const id = a => a;
const not = a => !a;
const takeWhile = (f, xs) => takeUntil(compose(not, f), xs);
const takeTruthy = xs => takeWhile(id, xs);
@slikts
Copy link
Author

slikts commented Mar 11, 2018

const compose = (f, g) => a => f(g(a));
const pipe = (...xs) => xs.reverse().reduce(compose);

@slikts
Copy link
Author

slikts commented Mar 11, 2018

const walk = (f, [x, ...xs], ys = []) => {
  const y = f(x)
  return y ? walk(f, xs, ys.concat(y)) : ys
}
// const walk = (f, [x, ...xs], ys = []) => (x = f(x)) ? walk(f, xs, ys.concat(x)) : ys

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment