<
const T extends ReadonlyArray<unknown>,
const I extends ReadonlyArray<Indices<T>>
>(
indices: I
): (self: T) => OmitTuple<T, I[number]>
<
const T extends ReadonlyArray<unknown>,
const I extends ReadonlyArray<Indices<T>>
>(
self: T,
indices: I
): OmitTuple<T, I[number]>Creates a new tuple with the elements at the specified indices removed.
When to use
Use to drop elements from a tuple by position.
Details
Elements not at the specified indices are kept in their original order.
Example (Removing elements by index)
import { Tuple } from "effect"
const result = Tuple.omit(["a", "b", "c", "d"], [1, 3])
console.log(result) // ["a", "c"]export const const omit: {
<
const T extends ReadonlyArray<unknown>,
const I extends ReadonlyArray<Indices<T>>
>(
indices: I
): (self: T) => OmitTuple<T, I[number]>
<
const T extends ReadonlyArray<unknown>,
const I extends ReadonlyArray<Indices<T>>
>(
self: T,
indices: I
): OmitTuple<T, I[number]>
}
Creates a new tuple with the elements at the specified indices removed.
When to use
Use to drop elements from a tuple by position.
Details
Elements not at the specified indices are kept in their original order.
Example (Removing elements by index)
import { Tuple } from "effect"
const result = Tuple.omit(["a", "b", "c", "d"], [1, 3])
console.log(result) // ["a", "c"]
omit: {
<const function (type parameter) T in <const T extends ReadonlyArray<unknown>, const I extends ReadonlyArray<Indices<T>>>(indices: I): (self: T) => OmitTuple<T, I[number]>T extends interface ReadonlyArray<T>ReadonlyArray<unknown>, const function (type parameter) I in <const T extends ReadonlyArray<unknown>, const I extends ReadonlyArray<Indices<T>>>(indices: I): (self: T) => OmitTuple<T, I[number]>I extends interface ReadonlyArray<T>ReadonlyArray<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>, const I extends ReadonlyArray<Indices<T>>>(indices: I): (self: T) => OmitTuple<T, I[number]>T>>>(
indices: const I extends ReadonlyArray<Indices<T>>indices: function (type parameter) I in <const T extends ReadonlyArray<unknown>, const I extends ReadonlyArray<Indices<T>>>(indices: I): (self: T) => OmitTuple<T, I[number]>I
): (self: const T extends ReadonlyArray<unknown>self: function (type parameter) T in <const T extends ReadonlyArray<unknown>, const I extends ReadonlyArray<Indices<T>>>(indices: I): (self: T) => OmitTuple<T, I[number]>T) => type OmitTuple<
T extends ReadonlyArray<unknown>,
K
> = 0 extends T["length"]
? []
: _BuildTuple<
T,
Exclude<
Exclude<
Partial<T>["length"],
T["length"]
>,
K
>,
0 extends Exclude<
Exclude<
Partial<T>["length"],
T["length"]
>,
K
>
? [
T[Exclude<
Exclude<
Partial<T>["length"],
T["length"]
>,
K
> &
0]
]
: [],
[unknown]
>
OmitTuple<function (type parameter) T in <const T extends ReadonlyArray<unknown>, const I extends ReadonlyArray<Indices<T>>>(indices: I): (self: T) => OmitTuple<T, I[number]>T, function (type parameter) I in <const T extends ReadonlyArray<unknown>, const I extends ReadonlyArray<Indices<T>>>(indices: I): (self: T) => OmitTuple<T, I[number]>I[number]>
<const function (type parameter) T in <const T extends ReadonlyArray<unknown>, const I extends ReadonlyArray<Indices<T>>>(self: T, indices: I): OmitTuple<T, I[number]>T extends interface ReadonlyArray<T>ReadonlyArray<unknown>, const function (type parameter) I in <const T extends ReadonlyArray<unknown>, const I extends ReadonlyArray<Indices<T>>>(self: T, indices: I): OmitTuple<T, I[number]>I extends interface ReadonlyArray<T>ReadonlyArray<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>, const I extends ReadonlyArray<Indices<T>>>(self: T, indices: I): OmitTuple<T, I[number]>T>>>(
self: const T extends ReadonlyArray<unknown>self: function (type parameter) T in <const T extends ReadonlyArray<unknown>, const I extends ReadonlyArray<Indices<T>>>(self: T, indices: I): OmitTuple<T, I[number]>T,
indices: const I extends ReadonlyArray<Indices<T>>indices: function (type parameter) I in <const T extends ReadonlyArray<unknown>, const I extends ReadonlyArray<Indices<T>>>(self: T, indices: I): OmitTuple<T, I[number]>I
): type OmitTuple<
T extends ReadonlyArray<unknown>,
K
> = 0 extends T["length"]
? []
: _BuildTuple<
T,
Exclude<
Exclude<
Partial<T>["length"],
T["length"]
>,
K
>,
0 extends Exclude<
Exclude<
Partial<T>["length"],
T["length"]
>,
K
>
? [
T[Exclude<
Exclude<
Partial<T>["length"],
T["length"]
>,
K
> &
0]
]
: [],
[unknown]
>
OmitTuple<function (type parameter) T in <const T extends ReadonlyArray<unknown>, const I extends ReadonlyArray<Indices<T>>>(self: T, indices: I): OmitTuple<T, I[number]>T, function (type parameter) I in <const T extends ReadonlyArray<unknown>, const I extends ReadonlyArray<Indices<T>>>(self: T, indices: I): OmitTuple<T, I[number]>I[number]>
} = dual<(...args: Array<any>) => any, <const T extends ReadonlyArray<unknown>>(self: T, indices: ReadonlyArray<number>) => unknown[]>(arity: 2, body: <const T extends ReadonlyArray<unknown>>(self: T, indices: ReadonlyArray<number>) => unknown[]): ((...args: Array<any>) => any) & (<const T extends ReadonlyArray<unknown>>(self: T, indices: ReadonlyArray<number>) => unknown[]) (+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,
<const function (type parameter) T in <const T extends ReadonlyArray<unknown>>(self: T, indices: ReadonlyArray<number>): unknown[]T extends interface ReadonlyArray<T>ReadonlyArray<unknown>>(
self: const T extends ReadonlyArray<unknown>self: function (type parameter) T in <const T extends ReadonlyArray<unknown>>(self: T, indices: ReadonlyArray<number>): unknown[]T,
indices: readonly number[]indices: interface ReadonlyArray<T>ReadonlyArray<number>
) => {
const const toDrop: Set<number>toDrop = new var Set: SetConstructor
new <number>(iterable?: Iterable<number> | null | undefined) => Set<number> (+1 overload)
Set<number>(indices: readonly number[]indices)
return self: const T extends ReadonlyArray<unknown>self.ReadonlyArray<unknown>.filter(predicate: (value: unknown, index: number, array: readonly unknown[]) => unknown, thisArg?: any): unknown[] (+1 overload)Returns the elements of an array that meet the condition specified in a callback function.
filter((_: unknown_, i: numberi) => !const toDrop: Set<number>toDrop.Set<number>.has(value: number): booleanhas(i: numberi))
}
)