Repeats values while passing predicate test.
value
- repeated valueindex
- original value indexcount
- repeats count thus far (starts with 0)state
- iteration stateimport {pipe, repeat} from 'iter-ops';
const i = pipe(
[1, 2, 3, 4, 5, 6, 7],
repeat((a, idx, c) => a % 2 === 0 && c < 2) // repeat even numbers 2 times
);
console.log(...i); //=> 1, 2, 2, 2, 3, 4, 4, 4, 5, 6, 6, 6, 7
Note that the predicate can only return a Promise
inside an asynchronous pipeline,
or else the Promise
will be treated as a truthy value.
Repeats every value specified number of times.