Skip to main content

consume

consume() function

Consumes the given number of Iterable/AsyncIterable. If the number is empty, all is consumed.

Signature:
declare function consume<A extends Iterable<unknown> | AsyncIterable<unknown>, B extends number>(iterator: A, n?: B): ReturnValueType<A, void>;

Example

const iterator = (function *(){
yield 1;
yield 2;
yield 3;
})();
consume(iterator, 2);
iterator.next(); // {value:3, done:false}
iterator.next(); // {value:undefined, done:true}

// with pipe
pipe(
range(10),
peek(updateApi),
concurrent(5),
consume,
);