Created
March 23, 2020 12:18
-
-
Save halan/02a432b7be193098f4c8134292abe732 to your computer and use it in GitHub Desktop.
Catamorph structure
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
Loop = (value, {x, y}) => ({ | |
value: value, | |
cata: mapping => | |
x > y | |
? value | |
: Loop(mapping(value, x), {x: x + 1, y}) | |
.cata(mapping) | |
}); | |
console.log( | |
Loop(0, {x: 0, y: 5}) | |
.cata((x, y) => x + y) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Maybe Range could be a better name here, instead Loop. Just thinking.