Skip to main content Link Search Menu Expand Document (external link)

Tuple overview

A simple extension to the Effect Tuple module


Table of contents


Constructors

fromSingleValue

Creates a one element tuple. MTuple.fromSingleValue must be used preferably to Tuple.make in functions that send a variable number of arguments like Array.map or Array.filter because a tuple with several arguments may accidentally be built. For instance, Array.map([1, 2, 3], Tuple.make) will return [[1,0], [2,1], [3,2]] whereas you might expect [[1], [2], [3]]. That’s because Array.map and Array.filter send a second argument with the position of the value.

Signature

export declare const fromSingleValue: <A>(a: A) => [A]

makeBoth

Creates a two element tuple with the same value

Signature

export declare const makeBoth: <A>(a: A) => [A, A]

makeBothBy

Creates a two element tuple applying two different functions to the same value

Signature

export declare const makeBothBy: <A, B, C = B>({
  toFirst,
  toSecond
}: {
  readonly toFirst: (a: NoInfer<A>) => B
  readonly toSecond: (a: NoInfer<A>) => C
}) => (a: A) => [B, C]

Utils

firstTwo

Returns the first two elements of a tuple

Signature

export declare const firstTwo: <A, B, C extends ReadonlyArray<unknown>>(a: readonly [A, B, ...C]) => [A, B]

prependElement

Prepends an element at the start of a tuple.

Signature

export declare const prependElement: <B>(that: B) => <A extends ReadonlyArray<unknown>>(self: A) => [B, ...A]