yta
    Preparing search index...

    Function flatRepeat

    • Create an iterator that repeats n times (defaults to indefinitely). After finishing one run a new iterator will be created from the generator and amended to the sequence. It is the same as running repeat on a generator and then flat.

      import { pipe } from "yta";
      import { flatRepeat, of, take, toArray } from "yta/async";

      pipe(
      flatRepeat(() => of(1, -1)),
      take(5),
      toArray(),
      );
      // => [1, -1, 1, -1, 1]

      If you provide n as a second argument, repeat the sequence n many times.

      import { pipe } from "yta";
      import { flatRepeat, of, toArray } from "yta/async";

      await pipe(
      flatRepeat(() => of(1, -1), 3),
      toArray(),
      );
      // => [1, -1, 1, -1, 1, -1]

      See also:

      Type Parameters

      • A

      Parameters

      • generator: () => AsyncIterable<A>
      • Optionaltimes: number = Number.POSITIVE_INFINITY

      Returns AsyncIterable<A, any, any>