<
const T extends ReadonlyArray<unknown>,
const I extends ReadonlyArray<Indices<T>>
>(
indices: I
): (self: T) => PickTuple<T, I[number]>
<
const T extends ReadonlyArray<unknown>,
const I extends ReadonlyArray<Indices<T>>
>(
self: T,
indices: I
): PickTuple<T, I[number]>Creates a new tuple containing only the elements at the specified indices.
When to use
Use to select a subset of elements from a tuple by position.
Details
The result order matches the order of the provided indices.
Example (Selecting elements by index)
import { Tuple } from "effect"
const result = Tuple.pick(["a", "b", "c", "d"], [0, 2, 3])
console.log(result) // ["a", "c", "d"]Source effect/Tuple.ts:12217 lines
export const const pick: {
<
const T extends ReadonlyArray<unknown>,
const I extends ReadonlyArray<Indices<T>>
>(
indices: I
): (self: T) => PickTuple<T, I[number]>
<
const T extends ReadonlyArray<unknown>,
const I extends ReadonlyArray<Indices<T>>
>(
self: T,
indices: I
): PickTuple<T, I[number]>
}
Creates a new tuple containing only the elements at the specified indices.
When to use
Use to select a subset of elements from a tuple by position.
Details
The result order matches the order of the provided indices.
Example (Selecting elements by index)
import { Tuple } from "effect"
const result = Tuple.pick(["a", "b", "c", "d"], [0, 2, 3])
console.log(result) // ["a", "c", "d"]
pick: {
<const function (type parameter) T in <const T extends ReadonlyArray<unknown>, const I extends ReadonlyArray<Indices<T>>>(indices: I): (self: T) => PickTuple<T, I[number]>T extends interface ReadonlyArray<T>ReadonlyArray<unknown>, const function (type parameter) I in <const T extends ReadonlyArray<unknown>, const I extends ReadonlyArray<Indices<T>>>(indices: I): (self: T) => PickTuple<T, I[number]>I extends interface ReadonlyArray<T>ReadonlyArray<type Indices<
T extends ReadonlyArray<unknown>
> = Partial<T>["length"] extends T["length"]
? never
: Partial<T>["length"]
Indices<function (type parameter) T in <const T extends ReadonlyArray<unknown>, const I extends ReadonlyArray<Indices<T>>>(indices: I): (self: T) => PickTuple<T, I[number]>T>>>(
indices: const I extends ReadonlyArray<Indices<T>>indices: function (type parameter) I in <const T extends ReadonlyArray<unknown>, const I extends ReadonlyArray<Indices<T>>>(indices: I): (self: T) => PickTuple<T, I[number]>I
): (self: const T extends ReadonlyArray<unknown>self: function (type parameter) T in <const T extends ReadonlyArray<unknown>, const I extends ReadonlyArray<Indices<T>>>(indices: I): (self: T) => PickTuple<T, I[number]>T) => type PickTuple<
T extends ReadonlyArray<unknown>,
K
> = 0 extends T["length"]
? []
: _BuildTuple<
T,
K,
0 extends K ? [T[K & 0]] : [],
[unknown]
>
PickTuple<function (type parameter) T in <const T extends ReadonlyArray<unknown>, const I extends ReadonlyArray<Indices<T>>>(indices: I): (self: T) => PickTuple<T, I[number]>T, function (type parameter) I in <const T extends ReadonlyArray<unknown>, const I extends ReadonlyArray<Indices<T>>>(indices: I): (self: T) => PickTuple<T, I[number]>I[number]>
<const function (type parameter) T in <const T extends ReadonlyArray<unknown>, const I extends ReadonlyArray<Indices<T>>>(self: T, indices: I): PickTuple<T, I[number]>T extends interface ReadonlyArray<T>ReadonlyArray<unknown>, const function (type parameter) I in <const T extends ReadonlyArray<unknown>, const I extends ReadonlyArray<Indices<T>>>(self: T, indices: I): PickTuple<T, I[number]>I extends interface ReadonlyArray<T>ReadonlyArray<type Indices<
T extends ReadonlyArray<unknown>
> = Partial<T>["length"] extends T["length"]
? never
: Partial<T>["length"]
Indices<function (type parameter) T in <const T extends ReadonlyArray<unknown>, const I extends ReadonlyArray<Indices<T>>>(self: T, indices: I): PickTuple<T, I[number]>T>>>(
self: const T extends ReadonlyArray<unknown>self: function (type parameter) T in <const T extends ReadonlyArray<unknown>, const I extends ReadonlyArray<Indices<T>>>(self: T, indices: I): PickTuple<T, I[number]>T,
indices: const I extends ReadonlyArray<Indices<T>>indices: function (type parameter) I in <const T extends ReadonlyArray<unknown>, const I extends ReadonlyArray<Indices<T>>>(self: T, indices: I): PickTuple<T, I[number]>I
): type PickTuple<
T extends ReadonlyArray<unknown>,
K
> = 0 extends T["length"]
? []
: _BuildTuple<
T,
K,
0 extends K ? [T[K & 0]] : [],
[unknown]
>
PickTuple<function (type parameter) T in <const T extends ReadonlyArray<unknown>, const I extends ReadonlyArray<Indices<T>>>(self: T, indices: I): PickTuple<T, I[number]>T, function (type parameter) I in <const T extends ReadonlyArray<unknown>, const I extends ReadonlyArray<Indices<T>>>(self: T, indices: I): PickTuple<T, I[number]>I[number]>
} = import dualdual(
2,
<const function (type parameter) T in <const T extends ReadonlyArray<unknown>>(self: T, indices: ReadonlyArray<number>): unknown[]T extends interface ReadonlyArray<T>ReadonlyArray<unknown>>(
self: const T extends ReadonlyArray<unknown>self: function (type parameter) T in <const T extends ReadonlyArray<unknown>>(self: T, indices: ReadonlyArray<number>): unknown[]T,
indices: readonly number[]indices: interface ReadonlyArray<T>ReadonlyArray<number>
) => {
return indices: readonly number[]indices.ReadonlyArray<number>.map<unknown>(callbackfn: (value: number, index: number, array: readonly number[]) => unknown, thisArg?: any): unknown[]Calls a defined callback function on each element of an array, and returns an array that contains the results.
map((i: numberi) => self: const T extends ReadonlyArray<unknown>self[i: numberi])
}
)