Hyperlinkv0.8.0-beta.28

Tuple

Tuple.pickconsteffect/Tuple.ts:122
<
  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"]
filteringomitget
Source effect/Tuple.ts:12217 lines
export 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]>
} = dual(
  2,
  <const T extends ReadonlyArray<unknown>>(
    self: T,
    indices: ReadonlyArray<number>
  ) => {
    return indices.map((i) => self[i])
  }
)