Skip to content

Instantly share code, notes, and snippets.

@ivenmarquardt
Last active October 18, 2016 10:06
Show Gist options
  • Select an option

  • Save ivenmarquardt/6d4c916a74d1a8ba8b716f288c7b6c41 to your computer and use it in GitHub Desktop.

Select an option

Save ivenmarquardt/6d4c916a74d1a8ba8b716f288c7b6c41 to your computer and use it in GitHub Desktop.
Paramorphism, extended catamorphism, fold, iteration
const paralk = f => acc => xs => {
const next = (acc, [head, ...tail]) => head === undefined
? acc
: f(acc) (head, tail, acc => next(acc, tail));
return next(acc, xs);
};
const drop = n => paralk(acc => (x, tail, k) => acc.length + 1 === n ? tail : (acc.push(x), k(acc))) ([]);
drop(3) ([1,2,3,4,5]); // yields [4,5]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment