Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@halan
Created March 23, 2020 12:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save halan/02a432b7be193098f4c8134292abe732 to your computer and use it in GitHub Desktop.
Save halan/02a432b7be193098f4c8134292abe732 to your computer and use it in GitHub Desktop.
Catamorph structure
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)
)
@halan
Copy link
Author

halan commented Mar 23, 2020

Maybe Range could be a better name here, instead Loop. Just thinking.

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