@mikuroxina/mini-fn
    Preparing search index...

    Function unfoldR

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

      Type Parameters

      • T
      • U

      Parameters

      • unfolder: (u: U) => Option.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: U) => List.List<T>

      The built list.

      Examples

      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,
      ]);