common-stuff
    Preparing search index...

    Function take

    • Returns a new container with the first n elements of the input, preserving the original container type.

      For AsyncIterable/Iterable the result is lazy and stops the source iterator after n elements. Negative n is treated as 0.

      Type Parameters

      • V

      Parameters

      • input: V[]
      • n: number

      Returns V[]

      take([1, 2, 3, 4], 2)            // [1, 2]
      take(new Set([1, 2, 3]), 2) // Set { 1, 2 }
      take({ a: 1, b: 2, c: 3 }, 2) // { a: 1, b: 2 }
    • Returns a new container with the first n elements of the input, preserving the original container type.

      For AsyncIterable/Iterable the result is lazy and stops the source iterator after n elements. Negative n is treated as 0.

      Type Parameters

      • K
      • V

      Parameters

      • input: Map<K, V>
      • n: number

      Returns Map<K, V>

      take([1, 2, 3, 4], 2)            // [1, 2]
      take(new Set([1, 2, 3]), 2) // Set { 1, 2 }
      take({ a: 1, b: 2, c: 3 }, 2) // { a: 1, b: 2 }
    • Returns a new container with the first n elements of the input, preserving the original container type.

      For AsyncIterable/Iterable the result is lazy and stops the source iterator after n elements. Negative n is treated as 0.

      Type Parameters

      • T

      Parameters

      • input: Set<T>
      • n: number

      Returns Set<T>

      take([1, 2, 3, 4], 2)            // [1, 2]
      take(new Set([1, 2, 3]), 2) // Set { 1, 2 }
      take({ a: 1, b: 2, c: 3 }, 2) // { a: 1, b: 2 }
    • Returns a new container with the first n elements of the input, preserving the original container type.

      For AsyncIterable/Iterable the result is lazy and stops the source iterator after n elements. Negative n is treated as 0.

      Type Parameters

      • T

      Parameters

      • input: AsyncIterable<T>
      • n: number

      Returns AsyncIterable<T>

      take([1, 2, 3, 4], 2)            // [1, 2]
      take(new Set([1, 2, 3]), 2) // Set { 1, 2 }
      take({ a: 1, b: 2, c: 3 }, 2) // { a: 1, b: 2 }
    • Returns a new container with the first n elements of the input, preserving the original container type.

      For AsyncIterable/Iterable the result is lazy and stops the source iterator after n elements. Negative n is treated as 0.

      Type Parameters

      • T

      Parameters

      • input: Iterable<T>
      • n: number

      Returns Iterable<T>

      take([1, 2, 3, 4], 2)            // [1, 2]
      take(new Set([1, 2, 3]), 2) // Set { 1, 2 }
      take({ a: 1, b: 2, c: 3 }, 2) // { a: 1, b: 2 }
    • Returns a new container with the first n elements of the input, preserving the original container type.

      For AsyncIterable/Iterable the result is lazy and stops the source iterator after n elements. Negative n is treated as 0.

      Type Parameters

      • K extends PropertyKey
      • V

      Parameters

      • input: Record<K, V>
      • n: number

      Returns Record<K, V>

      take([1, 2, 3, 4], 2)            // [1, 2]
      take(new Set([1, 2, 3]), 2) // Set { 1, 2 }
      take({ a: 1, b: 2, c: 3 }, 2) // { a: 1, b: 2 }