• Builds the list from initial value with unfolder. When unfolder returns none, the building will end.

    Type Parameters

    • T

    • U

    Parameters

    • unfolder: ((u) => Option<[T, U]>)

      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.

    Returns ((initial) => List<T>)

    The built list.

    Examples

    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,
    ]);
      • (initial): List<T>
      • Parameters

        • initial: U

        Returns List<T>

Generated using TypeDoc