The built list.
import { unfoldR, toArray } from "./list.ts";
import * as Option from "./option.ts";
import { assertEquals } from "../deps.ts";
const decrement = (n: number): Option.Option<[number, number]> => {
if (n == 0) {
return Option.none();
}
return Option.some([n, n - 1]);
};
assertEquals(toArray(unfoldR(decrement)(10)), [
10,
9,
8,
7,
6,
5,
4,
3,
2,
1,
]);
Generated using TypeDoc
Builds the list from
initial
value withunfolder
. Whenunfolder
returnsnone
, the building will end.