Hyperlinkv0.8.0-beta.28

Tuple

Tuple.mapOmitconsteffect/Tuple.ts:494
<
  const T extends ReadonlyArray<unknown>,
  const I extends ReadonlyArray<Indices<T>>,
  L extends Lambda
>(
  indices: I,
  lambda: L
): (self: T) => {
  [K in keyof T]: K extends `${I[number]}` ? T[K] : Apply<L, T[K]>
}
<
  const T extends ReadonlyArray<unknown>,
  const I extends ReadonlyArray<Indices<T>>,
  L extends Lambda
>(
  self: T,
  indices: I,
  lambda: L
): { [K in keyof T]: K extends `${I[number]}` ? T[K] : Apply<L, T[K]> }

Applies a Struct.Lambda transformation to all elements except those at the specified indices; the excluded elements are copied unchanged.

When to use

Use when most elements should be transformed but a few should be preserved.

Example (Wrapping all elements except one in arrays)

import { pipe, Struct, Tuple } from "effect"

interface AsArray extends Struct.Lambda {
  <A>(self: A): Array<A>
  readonly "~lambda.out": Array<this["~lambda.in"]>
}

const asArray = Struct.lambda<AsArray>((a) => [a])
const result = pipe(
  Tuple.make(1, "hello", true),
  Tuple.mapOmit([1], asArray)
)
console.log(result) // [[1], "hello", [true]]
mappingmapmapPick
Source effect/Tuple.ts:49423 lines
export const mapOmit: {
  <const T extends ReadonlyArray<unknown>, const I extends ReadonlyArray<Indices<T>>, L extends Lambda>(
    indices: I,
    lambda: L
  ): (
    self: T
  ) => { [K in keyof T]: K extends `${I[number]}` ? T[K] : Apply<L, T[K]> }
  <const T extends ReadonlyArray<unknown>, const I extends ReadonlyArray<Indices<T>>, L extends Lambda>(
    self: T,
    indices: I,
    lambda: L
  ): { [K in keyof T]: K extends `${I[number]}` ? T[K] : Apply<L, T[K]> }
} = dual(
  3,
  <const T extends ReadonlyArray<unknown>, L extends Function>(
    self: T,
    indices: ReadonlyArray<number>,
    lambda: L
  ) => {
    const toOmit = new Set<number>(indices)
    return self.map((e, i) => (toOmit.has(i) ? e : lambda(e)))
  }
)