Hyperlinkv0.8.0-beta.28

Tuple

Tuple.evolveconsteffect/Tuple.ts:291
<const T extends ReadonlyArray<unknown>, const E extends Evolver<T>>(
  evolver: E
): (self: T) => Evolved<T, E>
<const T extends ReadonlyArray<unknown>, const E extends Evolver<T>>(
  self: T,
  evolver: E
): Evolved<T, E>

Transforms elements of a tuple by providing an array of transform functions. Each function applies to the element at the same position. Positions beyond the array's length are copied unchanged.

When to use

Use when you want to update the first N elements while keeping the rest.

Details

Each transform function receives the current value and can return a different type.

Example (Transforming selected elements)

import { pipe, Tuple } from "effect"

const result = pipe(
  Tuple.make("hello", 42, true),
  Tuple.evolve([
    (s) => s.toUpperCase(),
    (n) => n * 2
  ])
)
console.log(result) // ["HELLO", 84, true]
Source effect/Tuple.ts:2919 lines
export const evolve: {
  <const T extends ReadonlyArray<unknown>, const E extends Evolver<T>>(evolver: E): (self: T) => Evolved<T, E>
  <const T extends ReadonlyArray<unknown>, const E extends Evolver<T>>(self: T, evolver: E): Evolved<T, E>
} = dual(
  2,
  <const T extends ReadonlyArray<unknown>, const E extends Evolver<T>>(self: T, evolver: E) => {
    return self.map((e, i) => (evolver[i] !== undefined ? evolver[i](e) : e))
  }
)