Hyperlinkv0.8.0-beta.28

Tuple

Tuple.appendElementconsteffect/Tuple.ts:210
<const E>(element: E): <const T extends ReadonlyArray<unknown>>(
  self: T
) => [...T, E]
<const T extends ReadonlyArray<unknown>, const E>(self: T, element: E): [
  ...T,
  E
]

Appends a single element to the end of a tuple.

When to use

Use when you need the appended value to remain part of the tuple's type-level shape and preserve literal element positions.

Details

The result type is [...T, E], preserving all existing element types.

Example (Appending an element)

import { pipe, Tuple } from "effect"

const result = pipe(Tuple.make(1, 2), Tuple.appendElement("end"))
console.log(result) // [1, 2, "end"]
Source effect/Tuple.ts:2104 lines
export const appendElement: {
  <const E>(element: E): <const T extends ReadonlyArray<unknown>>(self: T) => [...T, E]
  <const T extends ReadonlyArray<unknown>, const E>(self: T, element: E): [...T, E]
} = dual(2, <T extends ReadonlyArray<unknown>, E>(self: T, element: E): [...T, E] => [...self, element])