yta
    Preparing search index...

    Function recurrent

    • Generate a sequence with a recurrent relationship by applying a function to the previous state. Similar to accumulate but generates a new sequence from scratch.

      import { pipe } from "yta";
      import { map, recurrent, take, toArray } from "yta/async";

      await pipe(
      recurrent(([a, b]) => [b, a + b], [0, 1]),
      take(11),
      map(([a]) => a),
      toArray(),
      );
      // => [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55]

      See also:

      Type Parameters

      • A

      Parameters

      • fn: (state: A) => A | Promise<A>
      • init: A | Promise<A>

      Returns AsyncGenerator<A, void, any>