@mirei/ts-collections
    Preparing search index...

    Function take

    • Returns up to the specified number of leading elements from source.

      Type Parameters

      • TElement

        Type of elements within source.

      Parameters

      • source: Iterable<TElement>

        The source iterable.

      • count: number

        Number of elements to emit; values less than or equal to zero produce an empty sequence.

      Returns IEnumerable<TElement>

      A deferred sequence containing at most count elements from the start of source.

      Enumeration stops once count elements have been yielded or the source sequence ends.

      const numbers = [1, 2, 3, 4, 5];
      const firstTwo = take(numbers, 2).toArray();
      console.log(firstTwo); // [1, 2]

      const emptyTake = take(numbers, 0).toArray();
      console.log(emptyTake); // []