<A>(predicate: (a: NoInfer<A>, i: number) => boolean): (
self: ReadonlyArray<A>
) => self is NonEmptyReadonlyArray<A>
<A>(
self: ReadonlyArray<A>,
predicate: (a: A, i: number) => boolean
): self is NonEmptyReadonlyArray<A>Checks whether at least one element satisfies the predicate. Narrows the type
to NonEmptyReadonlyArray on success.
Example (Testing for any match)
import { Array } from "effect"
console.log(Array.some([1, 3, 4], (x) => x % 2 === 0)) // true
console.log(Array.some([1, 3, 5], (x) => x % 2 === 0)) // falseexport const const some: {
<A>(
predicate: (
a: NoInfer<A>,
i: number
) => boolean
): (
self: ReadonlyArray<A>
) => self is NonEmptyReadonlyArray<A>
<A>(
self: ReadonlyArray<A>,
predicate: (a: A, i: number) => boolean
): self is NonEmptyReadonlyArray<A>
}
Checks whether at least one element satisfies the predicate. Narrows the type
to NonEmptyReadonlyArray on success.
Example (Testing for any match)
import { Array } from "effect"
console.log(Array.some([1, 3, 4], (x) => x % 2 === 0)) // true
console.log(Array.some([1, 3, 5], (x) => x % 2 === 0)) // false
some: {
<function (type parameter) A in <A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: ReadonlyArray<A>) => self is NonEmptyReadonlyArray<A>A>(
predicate: (a: NoInfer<A>, i: number) => booleanpredicate: (a: NoInfer<A>a: type NoInfer<A> = [A][A extends any ? 0 : never]Prevents TypeScript from inferring a type parameter from a specific
position.
When to use
Use when a function parameter must match an inferred type without becoming
an inference source.
Details
The parameter using NoInfer must still match the inferred type.
Example (Controlling inference)
import type { Types } from "effect"
declare function withDefault<T>(value: T, fallback: Types.NoInfer<T>): T
// T is inferred as "a" | "b" from the first argument only
const result = withDefault<"a" | "b">("a", "b")
NoInfer<function (type parameter) A in <A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: ReadonlyArray<A>) => self is NonEmptyReadonlyArray<A>A>, i: numberi: number) => boolean
): (self: readonly A[]self: interface ReadonlyArray<T>ReadonlyArray<function (type parameter) A in <A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: ReadonlyArray<A>) => self is NonEmptyReadonlyArray<A>A>) => self: readonly A[]self is type NonEmptyReadonlyArray<A> = readonly [
A,
...A[]
]
A readonly array guaranteed to have at least one element.
When to use
Use when non-emptiness must be tracked at the type level while preventing mutation.
Many Array module functions accept or return this type.
Example (Typing a non-empty array)
import type { Array } from "effect"
const nonEmpty: Array.NonEmptyReadonlyArray<number> = [1, 2, 3]
const head: number = nonEmpty[0] // guaranteed to exist
NonEmptyReadonlyArray<function (type parameter) A in <A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: ReadonlyArray<A>) => self is NonEmptyReadonlyArray<A>A>
<function (type parameter) A in <A>(self: ReadonlyArray<A>, predicate: (a: A, i: number) => boolean): self is NonEmptyReadonlyArray<A>A>(self: readonly A[]self: interface ReadonlyArray<T>ReadonlyArray<function (type parameter) A in <A>(self: ReadonlyArray<A>, predicate: (a: A, i: number) => boolean): self is NonEmptyReadonlyArray<A>A>, predicate: (a: A, i: number) => booleanpredicate: (a: Aa: function (type parameter) A in <A>(self: ReadonlyArray<A>, predicate: (a: A, i: number) => boolean): self is NonEmptyReadonlyArray<A>A, i: numberi: number) => boolean): self: readonly A[]self is type NonEmptyReadonlyArray<A> = readonly [
A,
...A[]
]
A readonly array guaranteed to have at least one element.
When to use
Use when non-emptiness must be tracked at the type level while preventing mutation.
Many Array module functions accept or return this type.
Example (Typing a non-empty array)
import type { Array } from "effect"
const nonEmpty: Array.NonEmptyReadonlyArray<number> = [1, 2, 3]
const head: number = nonEmpty[0] // guaranteed to exist
NonEmptyReadonlyArray<function (type parameter) A in <A>(self: ReadonlyArray<A>, predicate: (a: A, i: number) => boolean): self is NonEmptyReadonlyArray<A>A>
} = dual<(...args: Array<any>) => any, <A>(self: ReadonlyArray<A>, predicate: (a: A, i: number) => boolean) => self is NonEmptyReadonlyArray<A>>(arity: 2, body: <A>(self: ReadonlyArray<A>, predicate: (a: A, i: number) => boolean) => self is NonEmptyReadonlyArray<A>): ((...args: Array<any>) => any) & (<A>(self: ReadonlyArray<A>, predicate: (a: A, i: number) => boolean) => self is NonEmptyReadonlyArray<A>) (+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) A in <A>(self: ReadonlyArray<A>, predicate: (a: A, i: number) => boolean): self is NonEmptyReadonlyArray<A>A>(self: readonly A[]self: interface ReadonlyArray<T>ReadonlyArray<function (type parameter) A in <A>(self: ReadonlyArray<A>, predicate: (a: A, i: number) => boolean): self is NonEmptyReadonlyArray<A>A>, predicate: (a: A, i: number) => booleanpredicate: (a: Aa: function (type parameter) A in <A>(self: ReadonlyArray<A>, predicate: (a: A, i: number) => boolean): self is NonEmptyReadonlyArray<A>A, i: numberi: number) => boolean): self: readonly A[]self is type NonEmptyReadonlyArray<A> = readonly [
A,
...A[]
]
A readonly array guaranteed to have at least one element.
When to use
Use when non-emptiness must be tracked at the type level while preventing mutation.
Many Array module functions accept or return this type.
Example (Typing a non-empty array)
import type { Array } from "effect"
const nonEmpty: Array.NonEmptyReadonlyArray<number> = [1, 2, 3]
const head: number = nonEmpty[0] // guaranteed to exist
NonEmptyReadonlyArray<function (type parameter) A in <A>(self: ReadonlyArray<A>, predicate: (a: A, i: number) => boolean): self is NonEmptyReadonlyArray<A>A> =>
self: readonly A[]self.globalThis.ReadonlyArray<A>.some(predicate: (value: A, index: number, array: readonly A[]) => unknown, thisArg?: any): booleanDetermines whether the specified callback function returns true for any element of an array.
some(predicate: (a: A, i: number) => booleanpredicate)
)