UNPKG

@stdlib/iter

Version:

Standard iterator utilities.

44 lines (32 loc) 1.07 kB
{{alias}}( iterator, n ) Returns an iterator which returns the first `n` values of a provided iterator. If a provided iterator only generates `m` values and `m` is less than `n`, the returned iterator only returns `m` values. If an environment supports Symbol.iterator and a provided iterator is iterable, the returned iterator is iterable. Parameters ---------- iterator: Object Input iterator. n: integer Number of values. Returns ------- iterator: Object Iterator. iterator.next(): Function Returns an iterator protocol-compliant object containing the next iterated value (if one exists) and a boolean flag indicating whether the iterator is finished. iterator.return( [value] ): Function Finishes an iterator and returns a provided value. Examples -------- > var it = {{alias}}( {{alias:@stdlib/random/iter/randu}}(), 5 ); > var r = it.next().value <number> > r = it.next().value <number> See Also --------