The type of values in the async iterable
Number of times to repeat the values (default: Infinity)
A transformer function that yields the input values repeated n times
This function creates a transformer that repeats values from an async iterable a specified number of times. It first collects all values into memory, then repeats them in sequence.
By default, the values repeat infinitely (n = Infinity). Be careful with infinite cycles -
they should be used with combinators like take to avoid infinite loops.
Special cases:
Note that all values are stored in memory, so be cautious with very large data sets.
// Repeat values 3 times
const repeated = await G.pipe(
G.ofIterable([1, 2, 3]),
G.cycle(3),
G.array
); // [1, 2, 3, 1, 2, 3, 1, 2, 3]
// Create an infinite cycle but take only 10 values
const tenValues = await G.pipe(
G.ofIterable(['a', 'b', 'c']),
G.cycle(), // Infinite cycle
G.take(10),
G.array
); // ['a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'c', 'a']
// Generate repeated patterns
const pattern = await G.pipe(
G.ofIterable([0, 1]),
G.cycle(4),
G.array
); // [0, 1, 0, 1, 0, 1, 0, 1]
Creates a transformer that repeats values from an async iterable multiple times.