<B, A, C>(that: NonEmptyReadonlyArray<B>, f: (a: A, b: B) => C): (
self: NonEmptyReadonlyArray<A>
) => NonEmptyArray<C>
<B, A, C>(that: Iterable<B>, f: (a: A, b: B) => C): (
self: Iterable<A>
) => Array<C>
<A, B, C>(
self: NonEmptyReadonlyArray<A>,
that: NonEmptyReadonlyArray<B>,
f: (a: A, b: B) => C
): NonEmptyArray<C>
<B, A, C>(
self: Iterable<A>,
that: Iterable<B>,
f: (a: A, b: B) => C
): Array<C>Combines elements from two iterables pairwise using a function. If the iterables differ in length, extra elements are discarded.
When to use
Use when zipping two iterables in an array pipeline and each pair should become a computed array element instead of a tuple.
Example (Zipping with addition)
import { Array } from "effect"
console.log(Array.zipWith([1, 2, 3], [4, 5, 6], (a, b) => a + b)) // [5, 7, 9]export const const zipWith: {
<B, A, C>(
that: NonEmptyReadonlyArray<B>,
f: (a: A, b: B) => C
): (
self: NonEmptyReadonlyArray<A>
) => NonEmptyArray<C>
<B, A, C>(
that: Iterable<B>,
f: (a: A, b: B) => C
): (self: Iterable<A>) => Array<C>
<A, B, C>(
self: NonEmptyReadonlyArray<A>,
that: NonEmptyReadonlyArray<B>,
f: (a: A, b: B) => C
): NonEmptyArray<C>
<B, A, C>(
self: Iterable<A>,
that: Iterable<B>,
f: (a: A, b: B) => C
): Array<C>
}
Combines elements from two iterables pairwise using a function. If the
iterables differ in length, extra elements are discarded.
When to use
Use when zipping two iterables in an array pipeline and each pair should
become a computed array element instead of a tuple.
Example (Zipping with addition)
import { Array } from "effect"
console.log(Array.zipWith([1, 2, 3], [4, 5, 6], (a, b) => a + b)) // [5, 7, 9]
zipWith: {
<function (type parameter) B in <B, A, C>(that: NonEmptyReadonlyArray<B>, f: (a: A, b: B) => C): (self: NonEmptyReadonlyArray<A>) => NonEmptyArray<C>B, function (type parameter) A in <B, A, C>(that: NonEmptyReadonlyArray<B>, f: (a: A, b: B) => C): (self: NonEmptyReadonlyArray<A>) => NonEmptyArray<C>A, function (type parameter) C in <B, A, C>(that: NonEmptyReadonlyArray<B>, f: (a: A, b: B) => C): (self: NonEmptyReadonlyArray<A>) => NonEmptyArray<C>C>(that: NonEmptyReadonlyArray<B>(parameter) that: {
0: B;
length: number;
toString: () => string;
toLocaleString: { (): string; (locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string };
concat: { (...items: Array<ConcatArray<B>>): Array<B>; (...items: Array<B | ConcatArray<B>>): Array<B> };
join: (separator?: string) => string;
slice: (start?: number, end?: number) => Array<B>;
indexOf: (searchElement: B, fromIndex?: number) => number;
lastIndexOf: (searchElement: B, fromIndex?: number) => number;
every: { (predicate: (value: B, index: number, array: ReadonlyArray<B>) => value is S, thisArg?: any): this is readonly S[]; (predicate: (value: B, index: number, array: ReadonlyArray<B>) => unknown, thisArg?: any): boolean };
some: (predicate: (value: B, index: number, array: ReadonlyArray<B>) => unknown, thisArg?: any) => boolean;
forEach: (callbackfn: (value: B, index: number, array: ReadonlyArray<B>) => void, thisArg?: any) => void;
map: (callbackfn: (value: B, index: number, array: ReadonlyArray<B>) => U, thisArg?: any) => Array<U>;
filter: { (predicate: (value: B, index: number, array: ReadonlyArray<B>) => value is S, thisArg?: any): Array<S>; (predicate: (value: B, index: number, array: ReadonlyArray<B>) => unknown, thisArg?: any): Array<B> };
reduce: { (callbackfn: (previousValue: B, currentValue: B, currentIndex: number, array: ReadonlyArray<B>) => B): B; (callbackfn: (previousValue: B, currentValue: B, currentIndex: number, array: ReadonlyArray<B>) => B, initialValue: B): B; (callbac…;
reduceRight: { (callbackfn: (previousValue: B, currentValue: B, currentIndex: number, array: ReadonlyArray<B>) => B): B; (callbackfn: (previousValue: B, currentValue: B, currentIndex: number, array: ReadonlyArray<B>) => B, initialValue: B): B; (callbac…;
find: { (predicate: (value: B, index: number, obj: ReadonlyArray<B>) => value is S, thisArg?: any): S | undefined; (predicate: (value: B, index: number, obj: ReadonlyArray<B>) => unknown, thisArg?: any): B | undefined };
findIndex: (predicate: (value: B, index: number, obj: ReadonlyArray<B>) => unknown, thisArg?: any) => number;
entries: () => ArrayIterator<[number, B]>;
keys: () => ArrayIterator<number>;
values: () => ArrayIterator<B>;
includes: (searchElement: B, fromIndex?: number) => boolean;
flatMap: (callback: (this: This, value: B, index: number, array: Array<B>) => U | ReadonlyArray<U>, thisArg?: This | undefined) => Array<U>;
flat: (this: A, depth?: D | undefined) => Array<FlatArray<A, D>>;
at: (index: number) => B | undefined;
findLast: { (predicate: (value: B, index: number, array: ReadonlyArray<B>) => value is S, thisArg?: any): S | undefined; (predicate: (value: B, index: number, array: ReadonlyArray<B>) => unknown, thisArg?: any): B | undefined };
findLastIndex: (predicate: (value: B, index: number, array: ReadonlyArray<B>) => unknown, thisArg?: any) => number;
toReversed: () => Array<B>;
toSorted: (compareFn?: ((a: B, b: B) => number) | undefined) => Array<B>;
toSpliced: { (start: number, deleteCount: number, ...items: Array<B>): Array<B>; (start: number, deleteCount?: number): Array<B> };
with: (index: number, value: B) => Array<B>;
}
that: 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) B in <B, A, C>(that: NonEmptyReadonlyArray<B>, f: (a: A, b: B) => C): (self: NonEmptyReadonlyArray<A>) => NonEmptyArray<C>B>, f: (a: A, b: B) => Cf: (a: Aa: function (type parameter) A in <B, A, C>(that: NonEmptyReadonlyArray<B>, f: (a: A, b: B) => C): (self: NonEmptyReadonlyArray<A>) => NonEmptyArray<C>A, b: Bb: function (type parameter) B in <B, A, C>(that: NonEmptyReadonlyArray<B>, f: (a: A, b: B) => C): (self: NonEmptyReadonlyArray<A>) => NonEmptyArray<C>B) => function (type parameter) C in <B, A, C>(that: NonEmptyReadonlyArray<B>, f: (a: A, b: B) => C): (self: NonEmptyReadonlyArray<A>) => NonEmptyArray<C>C): (self: NonEmptyReadonlyArray<A>(parameter) self: {
0: A;
length: number;
toString: () => string;
toLocaleString: { (): string; (locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string };
concat: { (...items: Array<ConcatArray<A>>): Array<A>; (...items: Array<A | ConcatArray<A>>): Array<A> };
join: (separator?: string) => string;
slice: (start?: number, end?: number) => Array<A>;
indexOf: (searchElement: A, fromIndex?: number) => number;
lastIndexOf: (searchElement: A, fromIndex?: number) => number;
every: { (predicate: (value: A, index: number, array: ReadonlyArray<A>) => value is S, thisArg?: any): this is readonly S[]; (predicate: (value: A, index: number, array: ReadonlyArray<A>) => unknown, thisArg?: any): boolean };
some: (predicate: (value: A, index: number, array: ReadonlyArray<A>) => unknown, thisArg?: any) => boolean;
forEach: (callbackfn: (value: A, index: number, array: ReadonlyArray<A>) => void, thisArg?: any) => void;
map: (callbackfn: (value: A, index: number, array: ReadonlyArray<A>) => U, thisArg?: any) => Array<U>;
filter: { (predicate: (value: A, index: number, array: ReadonlyArray<A>) => value is S, thisArg?: any): Array<S>; (predicate: (value: A, index: number, array: ReadonlyArray<A>) => unknown, thisArg?: any): Array<A> };
reduce: { (callbackfn: (previousValue: A, currentValue: A, currentIndex: number, array: ReadonlyArray<A>) => A): A; (callbackfn: (previousValue: A, currentValue: A, currentIndex: number, array: ReadonlyArray<A>) => A, initialValue: A): A; (callbac…;
reduceRight: { (callbackfn: (previousValue: A, currentValue: A, currentIndex: number, array: ReadonlyArray<A>) => A): A; (callbackfn: (previousValue: A, currentValue: A, currentIndex: number, array: ReadonlyArray<A>) => A, initialValue: A): A; (callbac…;
find: { (predicate: (value: A, index: number, obj: ReadonlyArray<A>) => value is S, thisArg?: any): S | undefined; (predicate: (value: A, index: number, obj: ReadonlyArray<A>) => unknown, thisArg?: any): A | undefined };
findIndex: (predicate: (value: A, index: number, obj: ReadonlyArray<A>) => unknown, thisArg?: any) => number;
entries: () => ArrayIterator<[number, A]>;
keys: () => ArrayIterator<number>;
values: () => ArrayIterator<A>;
includes: (searchElement: A, fromIndex?: number) => boolean;
flatMap: (callback: (this: This, value: A, index: number, array: Array<A>) => U | ReadonlyArray<U>, thisArg?: This | undefined) => Array<U>;
flat: (this: A, depth?: D | undefined) => Array<FlatArray<A, D>>;
at: (index: number) => A | undefined;
findLast: { (predicate: (value: A, index: number, array: ReadonlyArray<A>) => value is S, thisArg?: any): S | undefined; (predicate: (value: A, index: number, array: ReadonlyArray<A>) => unknown, thisArg?: any): A | undefined };
findLastIndex: (predicate: (value: A, index: number, array: ReadonlyArray<A>) => unknown, thisArg?: any) => number;
toReversed: () => Array<A>;
toSorted: (compareFn?: ((a: A, b: A) => number) | undefined) => Array<A>;
toSpliced: { (start: number, deleteCount: number, ...items: Array<A>): Array<A>; (start: number, deleteCount?: number): Array<A> };
with: (index: number, value: A) => Array<A>;
}
self: 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 <B, A, C>(that: NonEmptyReadonlyArray<B>, f: (a: A, b: B) => C): (self: NonEmptyReadonlyArray<A>) => NonEmptyArray<C>A>) => type NonEmptyArray<A> = [A, ...A[]]A mutable array guaranteed to have at least one element.
When to use
Use when mutation is acceptable and non-emptiness must be tracked at the type
level.
Details
This is the mutable counterpart of
NonEmptyReadonlyArray
. Most Array
module functions return NonEmptyArray when the result is guaranteed
non-empty.
Example (Typing a mutable non-empty array)
import type { Array } from "effect"
const nonEmpty: Array.NonEmptyArray<number> = [1, 2, 3]
nonEmpty.push(4)
NonEmptyArray<function (type parameter) C in <B, A, C>(that: NonEmptyReadonlyArray<B>, f: (a: A, b: B) => C): (self: NonEmptyReadonlyArray<A>) => NonEmptyArray<C>C>
<function (type parameter) B in <B, A, C>(that: Iterable<B>, f: (a: A, b: B) => C): (self: Iterable<A>) => Array<C>B, function (type parameter) A in <B, A, C>(that: Iterable<B>, f: (a: A, b: B) => C): (self: Iterable<A>) => Array<C>A, function (type parameter) C in <B, A, C>(that: Iterable<B>, f: (a: A, b: B) => C): (self: Iterable<A>) => Array<C>C>(that: Iterable<B>that: interface Iterable<T, TReturn = any, TNext = any>Iterable<function (type parameter) B in <B, A, C>(that: Iterable<B>, f: (a: A, b: B) => C): (self: Iterable<A>) => Array<C>B>, f: (a: A, b: B) => Cf: (a: Aa: function (type parameter) A in <B, A, C>(that: Iterable<B>, f: (a: A, b: B) => C): (self: Iterable<A>) => Array<C>A, b: Bb: function (type parameter) B in <B, A, C>(that: Iterable<B>, f: (a: A, b: B) => C): (self: Iterable<A>) => Array<C>B) => function (type parameter) C in <B, A, C>(that: Iterable<B>, f: (a: A, b: B) => C): (self: Iterable<A>) => Array<C>C): (self: Iterable<A>self: interface Iterable<T, TReturn = any, TNext = any>Iterable<function (type parameter) A in <B, A, C>(that: Iterable<B>, f: (a: A, b: B) => C): (self: Iterable<A>) => Array<C>A>) => interface Array<T>Array<function (type parameter) C in <B, A, C>(that: Iterable<B>, f: (a: A, b: B) => C): (self: Iterable<A>) => Array<C>C>
<function (type parameter) A in <A, B, C>(self: NonEmptyReadonlyArray<A>, that: NonEmptyReadonlyArray<B>, f: (a: A, b: B) => C): NonEmptyArray<C>A, function (type parameter) B in <A, B, C>(self: NonEmptyReadonlyArray<A>, that: NonEmptyReadonlyArray<B>, f: (a: A, b: B) => C): NonEmptyArray<C>B, function (type parameter) C in <A, B, C>(self: NonEmptyReadonlyArray<A>, that: NonEmptyReadonlyArray<B>, f: (a: A, b: B) => C): NonEmptyArray<C>C>(self: NonEmptyReadonlyArray<A>(parameter) self: {
0: A;
length: number;
toString: () => string;
toLocaleString: { (): string; (locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string };
concat: { (...items: Array<ConcatArray<A>>): Array<A>; (...items: Array<A | ConcatArray<A>>): Array<A> };
join: (separator?: string) => string;
slice: (start?: number, end?: number) => Array<A>;
indexOf: (searchElement: A, fromIndex?: number) => number;
lastIndexOf: (searchElement: A, fromIndex?: number) => number;
every: { (predicate: (value: A, index: number, array: ReadonlyArray<A>) => value is S, thisArg?: any): this is readonly S[]; (predicate: (value: A, index: number, array: ReadonlyArray<A>) => unknown, thisArg?: any): boolean };
some: (predicate: (value: A, index: number, array: ReadonlyArray<A>) => unknown, thisArg?: any) => boolean;
forEach: (callbackfn: (value: A, index: number, array: ReadonlyArray<A>) => void, thisArg?: any) => void;
map: (callbackfn: (value: A, index: number, array: ReadonlyArray<A>) => U, thisArg?: any) => Array<U>;
filter: { (predicate: (value: A, index: number, array: ReadonlyArray<A>) => value is S, thisArg?: any): Array<S>; (predicate: (value: A, index: number, array: ReadonlyArray<A>) => unknown, thisArg?: any): Array<A> };
reduce: { (callbackfn: (previousValue: A, currentValue: A, currentIndex: number, array: ReadonlyArray<A>) => A): A; (callbackfn: (previousValue: A, currentValue: A, currentIndex: number, array: ReadonlyArray<A>) => A, initialValue: A): A; (callbac…;
reduceRight: { (callbackfn: (previousValue: A, currentValue: A, currentIndex: number, array: ReadonlyArray<A>) => A): A; (callbackfn: (previousValue: A, currentValue: A, currentIndex: number, array: ReadonlyArray<A>) => A, initialValue: A): A; (callbac…;
find: { (predicate: (value: A, index: number, obj: ReadonlyArray<A>) => value is S, thisArg?: any): S | undefined; (predicate: (value: A, index: number, obj: ReadonlyArray<A>) => unknown, thisArg?: any): A | undefined };
findIndex: (predicate: (value: A, index: number, obj: ReadonlyArray<A>) => unknown, thisArg?: any) => number;
entries: () => ArrayIterator<[number, A]>;
keys: () => ArrayIterator<number>;
values: () => ArrayIterator<A>;
includes: (searchElement: A, fromIndex?: number) => boolean;
flatMap: (callback: (this: This, value: A, index: number, array: Array<A>) => U | ReadonlyArray<U>, thisArg?: This | undefined) => Array<U>;
flat: (this: A, depth?: D | undefined) => Array<FlatArray<A, D>>;
at: (index: number) => A | undefined;
findLast: { (predicate: (value: A, index: number, array: ReadonlyArray<A>) => value is S, thisArg?: any): S | undefined; (predicate: (value: A, index: number, array: ReadonlyArray<A>) => unknown, thisArg?: any): A | undefined };
findLastIndex: (predicate: (value: A, index: number, array: ReadonlyArray<A>) => unknown, thisArg?: any) => number;
toReversed: () => Array<A>;
toSorted: (compareFn?: ((a: A, b: A) => number) | undefined) => Array<A>;
toSpliced: { (start: number, deleteCount: number, ...items: Array<A>): Array<A>; (start: number, deleteCount?: number): Array<A> };
with: (index: number, value: A) => Array<A>;
}
self: 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, B, C>(self: NonEmptyReadonlyArray<A>, that: NonEmptyReadonlyArray<B>, f: (a: A, b: B) => C): NonEmptyArray<C>A>, that: NonEmptyReadonlyArray<B>(parameter) that: {
0: B;
length: number;
toString: () => string;
toLocaleString: { (): string; (locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string };
concat: { (...items: Array<ConcatArray<B>>): Array<B>; (...items: Array<B | ConcatArray<B>>): Array<B> };
join: (separator?: string) => string;
slice: (start?: number, end?: number) => Array<B>;
indexOf: (searchElement: B, fromIndex?: number) => number;
lastIndexOf: (searchElement: B, fromIndex?: number) => number;
every: { (predicate: (value: B, index: number, array: ReadonlyArray<B>) => value is S, thisArg?: any): this is readonly S[]; (predicate: (value: B, index: number, array: ReadonlyArray<B>) => unknown, thisArg?: any): boolean };
some: (predicate: (value: B, index: number, array: ReadonlyArray<B>) => unknown, thisArg?: any) => boolean;
forEach: (callbackfn: (value: B, index: number, array: ReadonlyArray<B>) => void, thisArg?: any) => void;
map: (callbackfn: (value: B, index: number, array: ReadonlyArray<B>) => U, thisArg?: any) => Array<U>;
filter: { (predicate: (value: B, index: number, array: ReadonlyArray<B>) => value is S, thisArg?: any): Array<S>; (predicate: (value: B, index: number, array: ReadonlyArray<B>) => unknown, thisArg?: any): Array<B> };
reduce: { (callbackfn: (previousValue: B, currentValue: B, currentIndex: number, array: ReadonlyArray<B>) => B): B; (callbackfn: (previousValue: B, currentValue: B, currentIndex: number, array: ReadonlyArray<B>) => B, initialValue: B): B; (callbac…;
reduceRight: { (callbackfn: (previousValue: B, currentValue: B, currentIndex: number, array: ReadonlyArray<B>) => B): B; (callbackfn: (previousValue: B, currentValue: B, currentIndex: number, array: ReadonlyArray<B>) => B, initialValue: B): B; (callbac…;
find: { (predicate: (value: B, index: number, obj: ReadonlyArray<B>) => value is S, thisArg?: any): S | undefined; (predicate: (value: B, index: number, obj: ReadonlyArray<B>) => unknown, thisArg?: any): B | undefined };
findIndex: (predicate: (value: B, index: number, obj: ReadonlyArray<B>) => unknown, thisArg?: any) => number;
entries: () => ArrayIterator<[number, B]>;
keys: () => ArrayIterator<number>;
values: () => ArrayIterator<B>;
includes: (searchElement: B, fromIndex?: number) => boolean;
flatMap: (callback: (this: This, value: B, index: number, array: Array<B>) => U | ReadonlyArray<U>, thisArg?: This | undefined) => Array<U>;
flat: (this: A, depth?: D | undefined) => Array<FlatArray<A, D>>;
at: (index: number) => B | undefined;
findLast: { (predicate: (value: B, index: number, array: ReadonlyArray<B>) => value is S, thisArg?: any): S | undefined; (predicate: (value: B, index: number, array: ReadonlyArray<B>) => unknown, thisArg?: any): B | undefined };
findLastIndex: (predicate: (value: B, index: number, array: ReadonlyArray<B>) => unknown, thisArg?: any) => number;
toReversed: () => Array<B>;
toSorted: (compareFn?: ((a: B, b: B) => number) | undefined) => Array<B>;
toSpliced: { (start: number, deleteCount: number, ...items: Array<B>): Array<B>; (start: number, deleteCount?: number): Array<B> };
with: (index: number, value: B) => Array<B>;
}
that: 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) B in <A, B, C>(self: NonEmptyReadonlyArray<A>, that: NonEmptyReadonlyArray<B>, f: (a: A, b: B) => C): NonEmptyArray<C>B>, f: (a: A, b: B) => Cf: (a: Aa: function (type parameter) A in <A, B, C>(self: NonEmptyReadonlyArray<A>, that: NonEmptyReadonlyArray<B>, f: (a: A, b: B) => C): NonEmptyArray<C>A, b: Bb: function (type parameter) B in <A, B, C>(self: NonEmptyReadonlyArray<A>, that: NonEmptyReadonlyArray<B>, f: (a: A, b: B) => C): NonEmptyArray<C>B) => function (type parameter) C in <A, B, C>(self: NonEmptyReadonlyArray<A>, that: NonEmptyReadonlyArray<B>, f: (a: A, b: B) => C): NonEmptyArray<C>C): type NonEmptyArray<A> = [A, ...A[]]A mutable array guaranteed to have at least one element.
When to use
Use when mutation is acceptable and non-emptiness must be tracked at the type
level.
Details
This is the mutable counterpart of
NonEmptyReadonlyArray
. Most Array
module functions return NonEmptyArray when the result is guaranteed
non-empty.
Example (Typing a mutable non-empty array)
import type { Array } from "effect"
const nonEmpty: Array.NonEmptyArray<number> = [1, 2, 3]
nonEmpty.push(4)
NonEmptyArray<function (type parameter) C in <A, B, C>(self: NonEmptyReadonlyArray<A>, that: NonEmptyReadonlyArray<B>, f: (a: A, b: B) => C): NonEmptyArray<C>C>
<function (type parameter) B in <B, A, C>(self: Iterable<A>, that: Iterable<B>, f: (a: A, b: B) => C): Array<C>B, function (type parameter) A in <B, A, C>(self: Iterable<A>, that: Iterable<B>, f: (a: A, b: B) => C): Array<C>A, function (type parameter) C in <B, A, C>(self: Iterable<A>, that: Iterable<B>, f: (a: A, b: B) => C): Array<C>C>(self: Iterable<A>self: interface Iterable<T, TReturn = any, TNext = any>Iterable<function (type parameter) A in <B, A, C>(self: Iterable<A>, that: Iterable<B>, f: (a: A, b: B) => C): Array<C>A>, that: Iterable<B>that: interface Iterable<T, TReturn = any, TNext = any>Iterable<function (type parameter) B in <B, A, C>(self: Iterable<A>, that: Iterable<B>, f: (a: A, b: B) => C): Array<C>B>, f: (a: A, b: B) => Cf: (a: Aa: function (type parameter) A in <B, A, C>(self: Iterable<A>, that: Iterable<B>, f: (a: A, b: B) => C): Array<C>A, b: Bb: function (type parameter) B in <B, A, C>(self: Iterable<A>, that: Iterable<B>, f: (a: A, b: B) => C): Array<C>B) => function (type parameter) C in <B, A, C>(self: Iterable<A>, that: Iterable<B>, f: (a: A, b: B) => C): Array<C>C): interface Array<T>Array<function (type parameter) C in <B, A, C>(self: Iterable<A>, that: Iterable<B>, f: (a: A, b: B) => C): Array<C>C>
} = dual<(...args: Array<any>) => any, <B, A, C>(self: Iterable<A>, that: Iterable<B>, f: (a: A, b: B) => C) => Array<C>>(arity: 3, body: <B, A, C>(self: Iterable<A>, that: Iterable<B>, f: (a: A, b: B) => C) => Array<C>): ((...args: Array<any>) => any) & (<B, A, C>(self: Iterable<A>, that: Iterable<B>, f: (a: A, b: B) => C) => Array<C>) (+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(3, <function (type parameter) B in <B, A, C>(self: Iterable<A>, that: Iterable<B>, f: (a: A, b: B) => C): Array<C>B, function (type parameter) A in <B, A, C>(self: Iterable<A>, that: Iterable<B>, f: (a: A, b: B) => C): Array<C>A, function (type parameter) C in <B, A, C>(self: Iterable<A>, that: Iterable<B>, f: (a: A, b: B) => C): Array<C>C>(self: Iterable<A>self: interface Iterable<T, TReturn = any, TNext = any>Iterable<function (type parameter) A in <B, A, C>(self: Iterable<A>, that: Iterable<B>, f: (a: A, b: B) => C): Array<C>A>, that: Iterable<B>that: interface Iterable<T, TReturn = any, TNext = any>Iterable<function (type parameter) B in <B, A, C>(self: Iterable<A>, that: Iterable<B>, f: (a: A, b: B) => C): Array<C>B>, f: (a: A, b: B) => Cf: (a: Aa: function (type parameter) A in <B, A, C>(self: Iterable<A>, that: Iterable<B>, f: (a: A, b: B) => C): Array<C>A, b: Bb: function (type parameter) B in <B, A, C>(self: Iterable<A>, that: Iterable<B>, f: (a: A, b: B) => C): Array<C>B) => function (type parameter) C in <B, A, C>(self: Iterable<A>, that: Iterable<B>, f: (a: A, b: B) => C): Array<C>C): interface Array<T>Array<function (type parameter) C in <B, A, C>(self: Iterable<A>, that: Iterable<B>, f: (a: A, b: B) => C): Array<C>C> => {
const const as: A[]as = const fromIterable: <A>(
collection: Iterable<A>
) => A[]
Converts an Iterable to an Array.
When to use
Use to convert any Iterable (Set, Generator, etc.) into an array.
Details
If the input is already an array, this returns it by reference without
copying. Otherwise, it creates a new array from the iterable. Use copy if
you need a fresh array even when the input is already an array.
Example (Converting a Set to an array)
import { Array } from "effect"
const result = Array.fromIterable(new Set([1, 2, 3]))
console.log(result) // [1, 2, 3]
fromIterable(self: Iterable<A>self)
const const bs: B[]bs = const fromIterable: <B>(
collection: Iterable<B>
) => B[]
Converts an Iterable to an Array.
When to use
Use to convert any Iterable (Set, Generator, etc.) into an array.
Details
If the input is already an array, this returns it by reference without
copying. Otherwise, it creates a new array from the iterable. Use copy if
you need a fresh array even when the input is already an array.
Example (Converting a Set to an array)
import { Array } from "effect"
const result = Array.fromIterable(new Set([1, 2, 3]))
console.log(result) // [1, 2, 3]
fromIterable(that: Iterable<B>that)
if (const isReadonlyArrayNonEmpty: <A>(
self: ReadonlyArray<A>
) => self is NonEmptyReadonlyArray<A>
Checks whether a ReadonlyArray is non-empty, narrowing the type to
NonEmptyReadonlyArray.
When to use
Use when you need to prove a readonly array has at least one element without
requiring mutable array methods afterward.
Example (Checking for a non-empty readonly array)
import { Array } from "effect"
console.log(Array.isReadonlyArrayNonEmpty([])) // false
console.log(Array.isReadonlyArrayNonEmpty([1, 2, 3])) // true
isReadonlyArrayNonEmpty(const as: A[]as) && const isReadonlyArrayNonEmpty: <A>(
self: ReadonlyArray<A>
) => self is NonEmptyReadonlyArray<A>
Checks whether a ReadonlyArray is non-empty, narrowing the type to
NonEmptyReadonlyArray.
When to use
Use when you need to prove a readonly array has at least one element without
requiring mutable array methods afterward.
Example (Checking for a non-empty readonly array)
import { Array } from "effect"
console.log(Array.isReadonlyArrayNonEmpty([])) // false
console.log(Array.isReadonlyArrayNonEmpty([1, 2, 3])) // true
isReadonlyArrayNonEmpty(const bs: B[]bs)) {
const const out: NonEmptyArray<C>const out: {
0: C;
length: number;
toString: () => string;
toLocaleString: { (): string; (locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string };
pop: () => C | undefined;
push: (...items: Array<C>) => number;
concat: { (...items: Array<ConcatArray<C>>): Array<C>; (...items: Array<C | ConcatArray<C>>): Array<C> };
join: (separator?: string) => string;
reverse: () => Array<C>;
shift: () => C | undefined;
slice: (start?: number, end?: number) => Array<C>;
sort: (compareFn?: ((a: C, b: C) => number) | undefined) => [C, ...C[]];
splice: { (start: number, deleteCount?: number): Array<C>; (start: number, deleteCount: number, ...items: Array<C>): Array<C> };
unshift: (...items: Array<C>) => number;
indexOf: (searchElement: C, fromIndex?: number) => number;
lastIndexOf: (searchElement: C, fromIndex?: number) => number;
every: { (predicate: (value: C, index: number, array: Array<C>) => value is S, thisArg?: any): this is S[]; (predicate: (value: C, index: number, array: Array<C>) => unknown, thisArg?: any): boolean };
some: (predicate: (value: C, index: number, array: Array<C>) => unknown, thisArg?: any) => boolean;
forEach: (callbackfn: (value: C, index: number, array: Array<C>) => void, thisArg?: any) => void;
map: (callbackfn: (value: C, index: number, array: Array<C>) => U, thisArg?: any) => Array<U>;
filter: { (predicate: (value: C, index: number, array: Array<C>) => value is S, thisArg?: any): Array<S>; (predicate: (value: C, index: number, array: Array<C>) => unknown, thisArg?: any): Array<C> };
reduce: { (callbackfn: (previousValue: C, currentValue: C, currentIndex: number, array: Array<C>) => C): C; (callbackfn: (previousValue: C, currentValue: C, currentIndex: number, array: Array<C>) => C, initialValue: C): C; (callbackfn: (previousVa…;
reduceRight: { (callbackfn: (previousValue: C, currentValue: C, currentIndex: number, array: Array<C>) => C): C; (callbackfn: (previousValue: C, currentValue: C, currentIndex: number, array: Array<C>) => C, initialValue: C): C; (callbackfn: (previousVa…;
find: { (predicate: (value: C, index: number, obj: Array<C>) => value is S, thisArg?: any): S | undefined; (predicate: (value: C, index: number, obj: Array<C>) => unknown, thisArg?: any): C | undefined };
findIndex: (predicate: (value: C, index: number, obj: Array<C>) => unknown, thisArg?: any) => number;
fill: (value: C, start?: number, end?: number) => [C, ...C[]];
copyWithin: (target: number, start: number, end?: number) => [C, ...C[]];
entries: () => ArrayIterator<[number, C]>;
keys: () => ArrayIterator<number>;
values: () => ArrayIterator<C>;
includes: (searchElement: C, fromIndex?: number) => boolean;
flatMap: (callback: (this: This, value: C, index: number, array: Array<C>) => U | ReadonlyArray<U>, thisArg?: This | undefined) => Array<U>;
flat: (this: A, depth?: D | undefined) => Array<FlatArray<A, D>>;
at: (index: number) => C | undefined;
findLast: { (predicate: (value: C, index: number, array: Array<C>) => value is S, thisArg?: any): S | undefined; (predicate: (value: C, index: number, array: Array<C>) => unknown, thisArg?: any): C | undefined };
findLastIndex: (predicate: (value: C, index: number, array: Array<C>) => unknown, thisArg?: any) => number;
toReversed: () => Array<C>;
toSorted: (compareFn?: ((a: C, b: C) => number) | undefined) => Array<C>;
toSpliced: { (start: number, deleteCount: number, ...items: Array<C>): Array<C>; (start: number, deleteCount?: number): Array<C> };
with: (index: number, value: C) => Array<C>;
}
out: type NonEmptyArray<A> = [A, ...A[]]A mutable array guaranteed to have at least one element.
When to use
Use when mutation is acceptable and non-emptiness must be tracked at the type
level.
Details
This is the mutable counterpart of
NonEmptyReadonlyArray
. Most Array
module functions return NonEmptyArray when the result is guaranteed
non-empty.
Example (Typing a mutable non-empty array)
import type { Array } from "effect"
const nonEmpty: Array.NonEmptyArray<number> = [1, 2, 3]
nonEmpty.push(4)
NonEmptyArray<function (type parameter) C in <B, A, C>(self: Iterable<A>, that: Iterable<B>, f: (a: A, b: B) => C): Array<C>C> = [f: (a: A, b: B) => Cf(const headNonEmpty: <A>(
self: NonEmptyReadonlyArray<A>
) => A
Returns the first element of a NonEmptyReadonlyArray directly (no Option
wrapper).
When to use
Use to get the first element without Option wrapping when the array is known
to be non-empty.
Example (Getting the head of a non-empty array)
import { Array } from "effect"
console.log(Array.headNonEmpty([1, 2, 3, 4])) // 1
headNonEmpty(const as: A[] & readonly [A, ...A[]]as), const headNonEmpty: <A>(
self: NonEmptyReadonlyArray<A>
) => A
Returns the first element of a NonEmptyReadonlyArray directly (no Option
wrapper).
When to use
Use to get the first element without Option wrapping when the array is known
to be non-empty.
Example (Getting the head of a non-empty array)
import { Array } from "effect"
console.log(Array.headNonEmpty([1, 2, 3, 4])) // 1
headNonEmpty(const bs: B[] & readonly [B, ...B[]]bs))]
const const len: numberlen = var Math: MathAn intrinsic object that provides basic mathematics functionality and constants.
Math.Math.min(...values: number[]): numberReturns the smaller of a set of supplied numeric expressions.
min(const as: A[] & readonly [A, ...A[]]as.Array<T>.length: numberGets or sets the length of the array. This is a number one higher than the highest index in the array.
length, const bs: B[] & readonly [B, ...B[]]bs.Array<T>.length: numberGets or sets the length of the array. This is a number one higher than the highest index in the array.
length)
for (let let i: numberi = 1; let i: numberi < const len: numberlen; let i: numberi++) {
const out: NonEmptyArray<C>const out: {
0: C;
length: number;
toString: () => string;
toLocaleString: { (): string; (locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string };
pop: () => C | undefined;
push: (...items: Array<C>) => number;
concat: { (...items: Array<ConcatArray<C>>): Array<C>; (...items: Array<C | ConcatArray<C>>): Array<C> };
join: (separator?: string) => string;
reverse: () => Array<C>;
shift: () => C | undefined;
slice: (start?: number, end?: number) => Array<C>;
sort: (compareFn?: ((a: C, b: C) => number) | undefined) => [C, ...C[]];
splice: { (start: number, deleteCount?: number): Array<C>; (start: number, deleteCount: number, ...items: Array<C>): Array<C> };
unshift: (...items: Array<C>) => number;
indexOf: (searchElement: C, fromIndex?: number) => number;
lastIndexOf: (searchElement: C, fromIndex?: number) => number;
every: { (predicate: (value: C, index: number, array: Array<C>) => value is S, thisArg?: any): this is S[]; (predicate: (value: C, index: number, array: Array<C>) => unknown, thisArg?: any): boolean };
some: (predicate: (value: C, index: number, array: Array<C>) => unknown, thisArg?: any) => boolean;
forEach: (callbackfn: (value: C, index: number, array: Array<C>) => void, thisArg?: any) => void;
map: (callbackfn: (value: C, index: number, array: Array<C>) => U, thisArg?: any) => Array<U>;
filter: { (predicate: (value: C, index: number, array: Array<C>) => value is S, thisArg?: any): Array<S>; (predicate: (value: C, index: number, array: Array<C>) => unknown, thisArg?: any): Array<C> };
reduce: { (callbackfn: (previousValue: C, currentValue: C, currentIndex: number, array: Array<C>) => C): C; (callbackfn: (previousValue: C, currentValue: C, currentIndex: number, array: Array<C>) => C, initialValue: C): C; (callbackfn: (previousVa…;
reduceRight: { (callbackfn: (previousValue: C, currentValue: C, currentIndex: number, array: Array<C>) => C): C; (callbackfn: (previousValue: C, currentValue: C, currentIndex: number, array: Array<C>) => C, initialValue: C): C; (callbackfn: (previousVa…;
find: { (predicate: (value: C, index: number, obj: Array<C>) => value is S, thisArg?: any): S | undefined; (predicate: (value: C, index: number, obj: Array<C>) => unknown, thisArg?: any): C | undefined };
findIndex: (predicate: (value: C, index: number, obj: Array<C>) => unknown, thisArg?: any) => number;
fill: (value: C, start?: number, end?: number) => [C, ...C[]];
copyWithin: (target: number, start: number, end?: number) => [C, ...C[]];
entries: () => ArrayIterator<[number, C]>;
keys: () => ArrayIterator<number>;
values: () => ArrayIterator<C>;
includes: (searchElement: C, fromIndex?: number) => boolean;
flatMap: (callback: (this: This, value: C, index: number, array: Array<C>) => U | ReadonlyArray<U>, thisArg?: This | undefined) => Array<U>;
flat: (this: A, depth?: D | undefined) => Array<FlatArray<A, D>>;
at: (index: number) => C | undefined;
findLast: { (predicate: (value: C, index: number, array: Array<C>) => value is S, thisArg?: any): S | undefined; (predicate: (value: C, index: number, array: Array<C>) => unknown, thisArg?: any): C | undefined };
findLastIndex: (predicate: (value: C, index: number, array: Array<C>) => unknown, thisArg?: any) => number;
toReversed: () => Array<C>;
toSorted: (compareFn?: ((a: C, b: C) => number) | undefined) => Array<C>;
toSpliced: { (start: number, deleteCount: number, ...items: Array<C>): Array<C>; (start: number, deleteCount?: number): Array<C> };
with: (index: number, value: C) => Array<C>;
}
out[let i: numberi] = f: (a: A, b: B) => Cf(const as: A[] & readonly [A, ...A[]]as[let i: numberi], const bs: B[] & readonly [B, ...B[]]bs[let i: numberi])
}
return const out: NonEmptyArray<C>const out: {
0: C;
length: number;
toString: () => string;
toLocaleString: { (): string; (locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string };
pop: () => C | undefined;
push: (...items: Array<C>) => number;
concat: { (...items: Array<ConcatArray<C>>): Array<C>; (...items: Array<C | ConcatArray<C>>): Array<C> };
join: (separator?: string) => string;
reverse: () => Array<C>;
shift: () => C | undefined;
slice: (start?: number, end?: number) => Array<C>;
sort: (compareFn?: ((a: C, b: C) => number) | undefined) => [C, ...C[]];
splice: { (start: number, deleteCount?: number): Array<C>; (start: number, deleteCount: number, ...items: Array<C>): Array<C> };
unshift: (...items: Array<C>) => number;
indexOf: (searchElement: C, fromIndex?: number) => number;
lastIndexOf: (searchElement: C, fromIndex?: number) => number;
every: { (predicate: (value: C, index: number, array: Array<C>) => value is S, thisArg?: any): this is S[]; (predicate: (value: C, index: number, array: Array<C>) => unknown, thisArg?: any): boolean };
some: (predicate: (value: C, index: number, array: Array<C>) => unknown, thisArg?: any) => boolean;
forEach: (callbackfn: (value: C, index: number, array: Array<C>) => void, thisArg?: any) => void;
map: (callbackfn: (value: C, index: number, array: Array<C>) => U, thisArg?: any) => Array<U>;
filter: { (predicate: (value: C, index: number, array: Array<C>) => value is S, thisArg?: any): Array<S>; (predicate: (value: C, index: number, array: Array<C>) => unknown, thisArg?: any): Array<C> };
reduce: { (callbackfn: (previousValue: C, currentValue: C, currentIndex: number, array: Array<C>) => C): C; (callbackfn: (previousValue: C, currentValue: C, currentIndex: number, array: Array<C>) => C, initialValue: C): C; (callbackfn: (previousVa…;
reduceRight: { (callbackfn: (previousValue: C, currentValue: C, currentIndex: number, array: Array<C>) => C): C; (callbackfn: (previousValue: C, currentValue: C, currentIndex: number, array: Array<C>) => C, initialValue: C): C; (callbackfn: (previousVa…;
find: { (predicate: (value: C, index: number, obj: Array<C>) => value is S, thisArg?: any): S | undefined; (predicate: (value: C, index: number, obj: Array<C>) => unknown, thisArg?: any): C | undefined };
findIndex: (predicate: (value: C, index: number, obj: Array<C>) => unknown, thisArg?: any) => number;
fill: (value: C, start?: number, end?: number) => [C, ...C[]];
copyWithin: (target: number, start: number, end?: number) => [C, ...C[]];
entries: () => ArrayIterator<[number, C]>;
keys: () => ArrayIterator<number>;
values: () => ArrayIterator<C>;
includes: (searchElement: C, fromIndex?: number) => boolean;
flatMap: (callback: (this: This, value: C, index: number, array: Array<C>) => U | ReadonlyArray<U>, thisArg?: This | undefined) => Array<U>;
flat: (this: A, depth?: D | undefined) => Array<FlatArray<A, D>>;
at: (index: number) => C | undefined;
findLast: { (predicate: (value: C, index: number, array: Array<C>) => value is S, thisArg?: any): S | undefined; (predicate: (value: C, index: number, array: Array<C>) => unknown, thisArg?: any): C | undefined };
findLastIndex: (predicate: (value: C, index: number, array: Array<C>) => unknown, thisArg?: any) => number;
toReversed: () => Array<C>;
toSorted: (compareFn?: ((a: C, b: C) => number) | undefined) => Array<C>;
toSpliced: { (start: number, deleteCount: number, ...items: Array<C>): Array<C>; (start: number, deleteCount?: number): Array<C> };
with: (index: number, value: C) => Array<C>;
}
out
}
return []
})