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] Copy
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.
n
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] Copy
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:
Optional
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.
If you provide
nas a second argument, repeat the sequencenmany times.See also: