Example 1 — Official: Count by Ten
Push the negated seed, add 10 to the seed, and stop once it passes 50.
const f = (n) => (n > 50 ? false : [-n, n + 10]);
console.log(R.unfold(f, 10)); // [-10, -20, -30, -40, -50] How It Works
- Start. Ramda calls
f(10). 10 is not above 50, so it returns[-10, 20]. - Push and move on.
-10goes into the list;20becomes the next seed. - Repeat. Seeds 20, 30, 40 and 50 push
-20through-50. - Stop.
f(60)returnsfalse, so the five values come back as the result.
