@nevware21/ts-utils
    Preparing search index...

    Function iterTake

    • Creates a lazy iterator that yields at most count values. The value is processed like for...of (and iterForOf), so an iterable (including a string or an array) is processed using its iterator (a string by its code points on a runtime which supports Symbol.iterator) and an iterator which is not iterable is used as-is. Unlike for...of (and iterForOf, which only also processes an array) any other array-like which is not iterable (eg. { length: 2, 0: "a", 1: "b" }, or arguments or a string on a runtime without Symbol.iterator) is processed using its indexes. A Map or Set which is not iterable (eg. on IE 11) is processed using a copy of its [key, value] entries / values, which is made when this is called (rather than when the first value is read), so a value added after that is not processed. Like the native iterator helpers a TypeError is thrown when the source's next() returns a value which is not an object, the source is closed (by calling its return() with no arguments) once the count is reached, it is done once the source throws, and its return() only closes the source when it isn't already done. Unlike the native take(), a negative or NaN count is used as 0 (so the source is closed by the first next()) rather than throwing a RangeError when it is created, and a fractional count is truncated.

      Type Parameters

      • T

      Parameters

      • iter: Iterator<T, any, undefined> | Iterable<T>
      • count: number

      Returns IterableIterator<T>

      TypeError when it is created if the value's [Symbol.iterator] isn't null, undefined or a function, from its next() (the iterator isn't checked when it is created) when the value's [Symbol.iterator]() doesn't return an iterator or the source's next() (or return(), when the count is reached) returns a value which is not an object, and from its return() when the source's return() returns a value which is not an object

      0.15.0

      const firstThree = iterTake([10, 20, 30, 40, 50], 3);
      iterToArray(firstThree); // [10, 20, 30]