Last active
October 18, 2016 10:06
-
-
Save ivenmarquardt/6d4c916a74d1a8ba8b716f288c7b6c41 to your computer and use it in GitHub Desktop.
Paramorphism, extended catamorphism, fold, iteration
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 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