<const T extends ReadonlyArray<unknown>, I extends Indices<T> & keyof T>(
index: I
): (self: T) => T[I]
<const T extends ReadonlyArray<unknown>, I extends Indices<T> & keyof T>(
self: T,
index: I
): T[I]Retrieves the element at the specified index from a tuple.
When to use
Use when a single tuple element should be extracted in a pipeline.
Details
The index is constrained to valid tuple positions at the type level.
Example (Extracting an element by index)
import { pipe, Tuple } from "effect"
const last = pipe(Tuple.make(1, true, "hello"), Tuple.get(2))
console.log(last) // "hello"export const const get: {
<
const T extends ReadonlyArray<unknown>,
I extends Indices<T> & keyof T
>(
index: I
): (self: T) => T[I]
<
const T extends ReadonlyArray<unknown>,
I extends Indices<T> & keyof T
>(
self: T,
index: I
): T[I]
}
Retrieves the element at the specified index from a tuple.
When to use
Use when a single tuple element should be extracted in a pipeline.
Details
The index is constrained to valid tuple positions at the type level.
Example (Extracting an element by index)
import { pipe, Tuple } from "effect"
const last = pipe(Tuple.make(1, true, "hello"), Tuple.get(2))
console.log(last) // "hello"
get: {
<const function (type parameter) T in <const T extends ReadonlyArray<unknown>, I extends Indices<T> & keyof T>(index: I): (self: T) => T[I]T extends interface ReadonlyArray<T>ReadonlyArray<unknown>, function (type parameter) I in <const T extends ReadonlyArray<unknown>, I extends Indices<T> & keyof T>(index: I): (self: T) => T[I]I extends type Indices<
T extends ReadonlyArray<unknown>
> = Partial<T>["length"] extends T["length"]
? never
: Partial<T>["length"]
Indices<function (type parameter) T in <const T extends ReadonlyArray<unknown>, I extends Indices<T> & keyof T>(index: I): (self: T) => T[I]T> & keyof function (type parameter) T in <const T extends ReadonlyArray<unknown>, I extends Indices<T> & keyof T>(index: I): (self: T) => T[I]T>(index: I extends Indices<T> & keyof Tindex: function (type parameter) I in <const T extends ReadonlyArray<unknown>, I extends Indices<T> & keyof T>(index: I): (self: T) => T[I]I): (self: const T extends ReadonlyArray<unknown>self: function (type parameter) T in <const T extends ReadonlyArray<unknown>, I extends Indices<T> & keyof T>(index: I): (self: T) => T[I]T) => function (type parameter) T in <const T extends ReadonlyArray<unknown>, I extends Indices<T> & keyof T>(index: I): (self: T) => T[I]T[function (type parameter) I in <const T extends ReadonlyArray<unknown>, I extends Indices<T> & keyof T>(index: I): (self: T) => T[I]I]
<const function (type parameter) T in <const T extends ReadonlyArray<unknown>, I extends Indices<T> & keyof T>(self: T, index: I): T[I]T extends interface ReadonlyArray<T>ReadonlyArray<unknown>, function (type parameter) I in <const T extends ReadonlyArray<unknown>, I extends Indices<T> & keyof T>(self: T, index: I): T[I]I extends type Indices<
T extends ReadonlyArray<unknown>
> = Partial<T>["length"] extends T["length"]
? never
: Partial<T>["length"]
Indices<function (type parameter) T in <const T extends ReadonlyArray<unknown>, I extends Indices<T> & keyof T>(self: T, index: I): T[I]T> & keyof function (type parameter) T in <const T extends ReadonlyArray<unknown>, I extends Indices<T> & keyof T>(self: T, index: I): T[I]T>(self: const T extends ReadonlyArray<unknown>self: function (type parameter) T in <const T extends ReadonlyArray<unknown>, I extends Indices<T> & keyof T>(self: T, index: I): T[I]T, index: I extends Indices<T> & keyof Tindex: function (type parameter) I in <const T extends ReadonlyArray<unknown>, I extends Indices<T> & keyof T>(self: T, index: I): T[I]I): function (type parameter) T in <const T extends ReadonlyArray<unknown>, I extends Indices<T> & keyof T>(self: T, index: I): T[I]T[function (type parameter) I in <const T extends ReadonlyArray<unknown>, I extends Indices<T> & keyof T>(self: T, index: I): T[I]I]
} = dual<(...args: Array<any>) => any, <T extends ReadonlyArray<unknown>, I extends keyof T>(self: T, index: I) => T[I]>(arity: 2, body: <T extends ReadonlyArray<unknown>, I extends keyof T>(self: T, index: I) => T[I]): ((...args: Array<any>) => any) & (<T extends ReadonlyArray<unknown>, I extends keyof T>(self: T, index: I) => T[I]) (+1 overload)Creates a function that can be called in data-first style or data-last
(pipe-friendly) style.
When to use
Use to expose one implementation through both direct and pipe-friendly
call styles.
Details
Pass either the arity of the uncurried function or a predicate that decides
whether the current call is data-first. Arity is the common case. Use a
predicate when optional arguments make arity ambiguous.
Example (Selecting data-first or data-last style by arity)
import { Function, pipe } from "effect"
const sum = Function.dual<
(that: number) => (self: number) => number,
(self: number, that: number) => number
>(2, (self, that) => self + that)
console.log(sum(2, 3)) // 5
console.log(pipe(2, sum(3))) // 5
Example (Defining overloads with call signatures)
import { Function, pipe } from "effect"
const sum: {
(that: number): (self: number) => number
(self: number, that: number): number
} = Function.dual(2, (self: number, that: number): number => self + that)
console.log(sum(2, 3)) // 5
console.log(pipe(2, sum(3))) // 5
Example (Selecting data-first or data-last style with a predicate)
import { Function, pipe } from "effect"
const sum = Function.dual<
(that: number) => (self: number) => number,
(self: number, that: number) => number
>(
(args) => args.length === 2,
(self, that) => self + that
)
console.log(sum(2, 3)) // 5
console.log(pipe(2, sum(3))) // 5
dual(2, <function (type parameter) T in <T extends ReadonlyArray<unknown>, I extends keyof T>(self: T, index: I): T[I]T extends interface ReadonlyArray<T>ReadonlyArray<unknown>, function (type parameter) I in <T extends ReadonlyArray<unknown>, I extends keyof T>(self: T, index: I): T[I]I extends keyof function (type parameter) T in <T extends ReadonlyArray<unknown>, I extends keyof T>(self: T, index: I): T[I]T>(self: T extends ReadonlyArray<unknown>self: function (type parameter) T in <T extends ReadonlyArray<unknown>, I extends keyof T>(self: T, index: I): T[I]T, index: I extends keyof Tindex: function (type parameter) I in <T extends ReadonlyArray<unknown>, I extends keyof T>(self: T, index: I): T[I]I): function (type parameter) T in <T extends ReadonlyArray<unknown>, I extends keyof T>(self: T, index: I): T[I]T[function (type parameter) I in <T extends ReadonlyArray<unknown>, I extends keyof T>(self: T, index: I): T[I]I] => self: T extends ReadonlyArray<unknown>self[index: I extends keyof Tindex])