Builds the list from initial value with unfolder. When unfolder returns none, the building will end.
initial
unfolder
none
The function takes the seed and returns the tuple of next element and seed. The seed will be used as the next seed in a recursive call.
The built list.
const decrement = (n: number): Option.Option<[number, number]> => { if (n == 0) { return Option.none(); } return Option.some([n, n - 1]);};expect(toArray(unfoldR(decrement)(10))).toStrictEqual([ 10, 9, 8, 7, 6, 5, 4, 3, 2, 1,]); Copy
const decrement = (n: number): Option.Option<[number, number]> => { if (n == 0) { return Option.none(); } return Option.some([n, n - 1]);};expect(toArray(unfoldR(decrement)(10))).toStrictEqual([ 10, 9, 8, 7, 6, 5, 4, 3, 2, 1,]);
Builds the list from
initialvalue withunfolder. Whenunfolderreturnsnone, the building will end.