<N extends number>(n: N): <T>(
self: ReadonlyArray<T>
) => self is TupleOfAtLeast<N, T>
<T, N extends number>(
self: ReadonlyArray<T>,
n: N
): self is TupleOfAtLeast<N, T>Checks whether a readonly array has at least n elements.
When to use
Use when you need a Predicate guard for tuple-like minimum length that
narrows ReadonlyArray<T> to TupleOfAtLeast<N, T>.
Details
This only checks length, not element types, and returns a refinement on the array type.
Example (Checking minimum length)
import { Predicate } from "effect"
const hasAtLeast2 = Predicate.isTupleOfAtLeast(2)
console.log(hasAtLeast2([1, 2, 3]))export const const isTupleOfAtLeast: {
<N extends number>(n: N): <T>(
self: ReadonlyArray<T>
) => self is TupleOfAtLeast<N, T>
<T, N extends number>(
self: ReadonlyArray<T>,
n: N
): self is TupleOfAtLeast<N, T>
}
Checks whether a readonly array has at least n elements.
When to use
Use when you need a Predicate guard for tuple-like minimum length that
narrows ReadonlyArray<T> to TupleOfAtLeast<N, T>.
Details
This only checks length, not element types, and returns a refinement on the
array type.
Example (Checking minimum length)
import { Predicate } from "effect"
const hasAtLeast2 = Predicate.isTupleOfAtLeast(2)
console.log(hasAtLeast2([1, 2, 3]))
isTupleOfAtLeast: {
<function (type parameter) N in <N extends number>(n: N): <T>(self: ReadonlyArray<T>) => self is TupleOfAtLeast<N, T>N extends number>(n: N extends numbern: function (type parameter) N in <N extends number>(n: N): <T>(self: ReadonlyArray<T>) => self is TupleOfAtLeast<N, T>N): <function (type parameter) T in <T>(self: ReadonlyArray<T>): self is TupleOfAtLeast<N, T>T>(self: readonly T[]self: interface ReadonlyArray<T>ReadonlyArray<function (type parameter) T in <T>(self: ReadonlyArray<T>): self is TupleOfAtLeast<N, T>T>) => self: readonly T[]self is type TupleOfAtLeast<N extends number, T> = [...TupleOf<N, T>, ...T[]]Constructs a tuple type with at least N elements of type T.
When to use
Use when you need a minimum-length array type that still allows additional
elements. This is useful for variadic function signatures that require a
minimum arity.
Details
Produces a tuple with N fixed positions followed by ...Array<T>.
Example (Checking minimum-length tuples)
import type { Types } from "effect"
// At least 2 strings
const ok1: Types.TupleOfAtLeast<2, string> = ["a", "b"]
const ok2: Types.TupleOfAtLeast<2, string> = ["a", "b", "c", "d"]
//
TupleOfAtLeast<function (type parameter) N in <N extends number>(n: N): <T>(self: ReadonlyArray<T>) => self is TupleOfAtLeast<N, T>N, function (type parameter) T in <T>(self: ReadonlyArray<T>): self is TupleOfAtLeast<N, T>T>
<function (type parameter) T in <T, N extends number>(self: ReadonlyArray<T>, n: N): self is TupleOfAtLeast<N, T>T, function (type parameter) N in <T, N extends number>(self: ReadonlyArray<T>, n: N): self is TupleOfAtLeast<N, T>N extends number>(self: readonly T[]self: interface ReadonlyArray<T>ReadonlyArray<function (type parameter) T in <T, N extends number>(self: ReadonlyArray<T>, n: N): self is TupleOfAtLeast<N, T>T>, n: N extends numbern: function (type parameter) N in <T, N extends number>(self: ReadonlyArray<T>, n: N): self is TupleOfAtLeast<N, T>N): self: readonly T[]self is type TupleOfAtLeast<N extends number, T> = [...TupleOf<N, T>, ...T[]]Constructs a tuple type with at least N elements of type T.
When to use
Use when you need a minimum-length array type that still allows additional
elements. This is useful for variadic function signatures that require a
minimum arity.
Details
Produces a tuple with N fixed positions followed by ...Array<T>.
Example (Checking minimum-length tuples)
import type { Types } from "effect"
// At least 2 strings
const ok1: Types.TupleOfAtLeast<2, string> = ["a", "b"]
const ok2: Types.TupleOfAtLeast<2, string> = ["a", "b", "c", "d"]
//
TupleOfAtLeast<function (type parameter) N in <T, N extends number>(self: ReadonlyArray<T>, n: N): self is TupleOfAtLeast<N, T>N, function (type parameter) T in <T, N extends number>(self: ReadonlyArray<T>, n: N): self is TupleOfAtLeast<N, T>T>
} = dual<(...args: Array<any>) => any, <T, N extends number>(self: ReadonlyArray<T>, n: N) => self is TupleOfAtLeast<N, T>>(arity: 2, body: <T, N extends number>(self: ReadonlyArray<T>, n: N) => self is TupleOfAtLeast<N, T>): ((...args: Array<any>) => any) & (<T, N extends number>(self: ReadonlyArray<T>, n: N) => self is TupleOfAtLeast<N, T>) (+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, N extends number>(self: ReadonlyArray<T>, n: N): self is TupleOfAtLeast<N, T>T, function (type parameter) N in <T, N extends number>(self: ReadonlyArray<T>, n: N): self is TupleOfAtLeast<N, T>N extends number>(self: readonly T[]self: interface ReadonlyArray<T>ReadonlyArray<function (type parameter) T in <T, N extends number>(self: ReadonlyArray<T>, n: N): self is TupleOfAtLeast<N, T>T>, n: N extends numbern: function (type parameter) N in <T, N extends number>(self: ReadonlyArray<T>, n: N): self is TupleOfAtLeast<N, T>N): self: readonly T[]self is type TupleOfAtLeast<N extends number, T> = [...TupleOf<N, T>, ...T[]]Constructs a tuple type with at least N elements of type T.
When to use
Use when you need a minimum-length array type that still allows additional
elements. This is useful for variadic function signatures that require a
minimum arity.
Details
Produces a tuple with N fixed positions followed by ...Array<T>.
Example (Checking minimum-length tuples)
import type { Types } from "effect"
// At least 2 strings
const ok1: Types.TupleOfAtLeast<2, string> = ["a", "b"]
const ok2: Types.TupleOfAtLeast<2, string> = ["a", "b", "c", "d"]
//
TupleOfAtLeast<function (type parameter) N in <T, N extends number>(self: ReadonlyArray<T>, n: N): self is TupleOfAtLeast<N, T>N, function (type parameter) T in <T, N extends number>(self: ReadonlyArray<T>, n: N): self is TupleOfAtLeast<N, T>T> => self: readonly T[]self.ReadonlyArray<T>.length: numberGets the length of the array. This is a number one higher than the highest element defined in an array.
length >= n: N extends numbern)