<A extends object, N extends string, B>(
tag: Exclude<N, keyof A>,
f: (a: NoInfer<A>) => ReadonlyArray<B>
): (
self: ReadonlyArray<A>
) => Array<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }>
<A extends object, N extends string, B>(
self: ReadonlyArray<A>,
tag: Exclude<N, keyof A>,
f: (a: NoInfer<A>) => ReadonlyArray<B>
): Array<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }>Adds a new array variable to a do-notation scope, producing the cartesian product with all previous bindings.
When to use
Use to add another array-producing binding to an Array.Do pipeline, pairing
each existing scope with every value returned by the callback.
Details
Each bind call adds a named property to the accumulated object. The
callback receives the current scope and must return an array. This is
equivalent to flatMap plus merging the new value into the scope object.
Example (Binding two arrays)
import { Array, pipe } from "effect"
const result = pipe(
Array.Do,
Array.bind("x", () => [1, 2]),
Array.bind("y", () => ["a", "b"])
)
console.log(result)
// [{ x: 1, y: "a" }, { x: 1, y: "b" }, { x: 2, y: "a" }, { x: 2, y: "b" }]export const const bind: {
<A extends object, N extends string, B>(
tag: Exclude<N, keyof A>,
f: (a: NoInfer<A>) => ReadonlyArray<B>
): (self: ReadonlyArray<A>) => Array<{
[K in N | keyof A]: K extends keyof A
? A[K]
: B
}>
<A extends object, N extends string, B>(
self: ReadonlyArray<A>,
tag: Exclude<N, keyof A>,
f: (a: NoInfer<A>) => ReadonlyArray<B>
): Array<{
[K in N | keyof A]: K extends keyof A
? A[K]
: B
}>
}
Adds a new array variable to a do-notation scope, producing the cartesian product with all previous bindings.
When to use
Use to add another array-producing binding to an Array.Do pipeline, pairing
each existing scope with every value returned by the callback.
Details
Each bind call adds a named property to the accumulated object. The
callback receives the current scope and must return an array. This is
equivalent to flatMap plus merging the new value into the scope object.
Example (Binding two arrays)
import { Array, pipe } from "effect"
const result = pipe(
Array.Do,
Array.bind("x", () => [1, 2]),
Array.bind("y", () => ["a", "b"])
)
console.log(result)
// [{ x: 1, y: "a" }, { x: 1, y: "b" }, { x: 2, y: "a" }, { x: 2, y: "b" }]
bind: {
<function (type parameter) A in <A extends object, N extends string, B>(tag: Exclude<N, keyof A>, f: (a: NoInfer<A>) => ReadonlyArray<B>): (self: ReadonlyArray<A>) => Array<{ [K in N | keyof A]: K extends keyof A ? A[K] : B; }>A extends object, function (type parameter) N in <A extends object, N extends string, B>(tag: Exclude<N, keyof A>, f: (a: NoInfer<A>) => ReadonlyArray<B>): (self: ReadonlyArray<A>) => Array<{ [K in N | keyof A]: K extends keyof A ? A[K] : B; }>N extends string, function (type parameter) B in <A extends object, N extends string, B>(tag: Exclude<N, keyof A>, f: (a: NoInfer<A>) => ReadonlyArray<B>): (self: ReadonlyArray<A>) => Array<{ [K in N | keyof A]: K extends keyof A ? A[K] : B; }>B>(
tag: Exclude<N, keyof A>tag: type Exclude<T, U> = T extends U
? never
: T
Exclude from T those types that are assignable to U
Exclude<function (type parameter) N in <A extends object, N extends string, B>(tag: Exclude<N, keyof A>, f: (a: NoInfer<A>) => ReadonlyArray<B>): (self: ReadonlyArray<A>) => Array<{ [K in N | keyof A]: K extends keyof A ? A[K] : B; }>N, keyof function (type parameter) A in <A extends object, N extends string, B>(tag: Exclude<N, keyof A>, f: (a: NoInfer<A>) => ReadonlyArray<B>): (self: ReadonlyArray<A>) => Array<{ [K in N | keyof A]: K extends keyof A ? A[K] : B; }>A>,
f: (a: NoInfer<A>) => ReadonlyArray<B>f: (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 extends object, N extends string, B>(tag: Exclude<N, keyof A>, f: (a: NoInfer<A>) => ReadonlyArray<B>): (self: ReadonlyArray<A>) => Array<{ [K in N | keyof A]: K extends keyof A ? A[K] : B; }>A>) => interface ReadonlyArray<T>ReadonlyArray<function (type parameter) B in <A extends object, N extends string, B>(tag: Exclude<N, keyof A>, f: (a: NoInfer<A>) => ReadonlyArray<B>): (self: ReadonlyArray<A>) => Array<{ [K in N | keyof A]: K extends keyof A ? A[K] : B; }>B>
): (
self: readonly A[]self: interface ReadonlyArray<T>ReadonlyArray<function (type parameter) A in <A extends object, N extends string, B>(tag: Exclude<N, keyof A>, f: (a: NoInfer<A>) => ReadonlyArray<B>): (self: ReadonlyArray<A>) => Array<{ [K in N | keyof A]: K extends keyof A ? A[K] : B; }>A>
) => interface Array<T>Array<{ [function (type parameter) KK in function (type parameter) N in <A extends object, N extends string, B>(tag: Exclude<N, keyof A>, f: (a: NoInfer<A>) => ReadonlyArray<B>): (self: ReadonlyArray<A>) => Array<{ [K in N | keyof A]: K extends keyof A ? A[K] : B; }>N | keyof function (type parameter) A in <A extends object, N extends string, B>(tag: Exclude<N, keyof A>, f: (a: NoInfer<A>) => ReadonlyArray<B>): (self: ReadonlyArray<A>) => Array<{ [K in N | keyof A]: K extends keyof A ? A[K] : B; }>A]: function (type parameter) KK extends keyof function (type parameter) A in <A extends object, N extends string, B>(tag: Exclude<N, keyof A>, f: (a: NoInfer<A>) => ReadonlyArray<B>): (self: ReadonlyArray<A>) => Array<{ [K in N | keyof A]: K extends keyof A ? A[K] : B; }>A ? function (type parameter) A in <A extends object, N extends string, B>(tag: Exclude<N, keyof A>, f: (a: NoInfer<A>) => ReadonlyArray<B>): (self: ReadonlyArray<A>) => Array<{ [K in N | keyof A]: K extends keyof A ? A[K] : B; }>A[function (type parameter) KK] : function (type parameter) B in <A extends object, N extends string, B>(tag: Exclude<N, keyof A>, f: (a: NoInfer<A>) => ReadonlyArray<B>): (self: ReadonlyArray<A>) => Array<{ [K in N | keyof A]: K extends keyof A ? A[K] : B; }>B }>
<function (type parameter) A in <A extends object, N extends string, B>(self: ReadonlyArray<A>, tag: Exclude<N, keyof A>, f: (a: NoInfer<A>) => ReadonlyArray<B>): Array<{ [K in N | keyof A]: K extends keyof A ? A[K] : B; }>A extends object, function (type parameter) N in <A extends object, N extends string, B>(self: ReadonlyArray<A>, tag: Exclude<N, keyof A>, f: (a: NoInfer<A>) => ReadonlyArray<B>): Array<{ [K in N | keyof A]: K extends keyof A ? A[K] : B; }>N extends string, function (type parameter) B in <A extends object, N extends string, B>(self: ReadonlyArray<A>, tag: Exclude<N, keyof A>, f: (a: NoInfer<A>) => ReadonlyArray<B>): Array<{ [K in N | keyof A]: K extends keyof A ? A[K] : B; }>B>(
self: readonly A[]self: interface ReadonlyArray<T>ReadonlyArray<function (type parameter) A in <A extends object, N extends string, B>(self: ReadonlyArray<A>, tag: Exclude<N, keyof A>, f: (a: NoInfer<A>) => ReadonlyArray<B>): Array<{ [K in N | keyof A]: K extends keyof A ? A[K] : B; }>A>,
tag: Exclude<N, keyof A>tag: type Exclude<T, U> = T extends U
? never
: T
Exclude from T those types that are assignable to U
Exclude<function (type parameter) N in <A extends object, N extends string, B>(self: ReadonlyArray<A>, tag: Exclude<N, keyof A>, f: (a: NoInfer<A>) => ReadonlyArray<B>): Array<{ [K in N | keyof A]: K extends keyof A ? A[K] : B; }>N, keyof function (type parameter) A in <A extends object, N extends string, B>(self: ReadonlyArray<A>, tag: Exclude<N, keyof A>, f: (a: NoInfer<A>) => ReadonlyArray<B>): Array<{ [K in N | keyof A]: K extends keyof A ? A[K] : B; }>A>,
f: (a: NoInfer<A>) => ReadonlyArray<B>f: (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 extends object, N extends string, B>(self: ReadonlyArray<A>, tag: Exclude<N, keyof A>, f: (a: NoInfer<A>) => ReadonlyArray<B>): Array<{ [K in N | keyof A]: K extends keyof A ? A[K] : B; }>A>) => interface ReadonlyArray<T>ReadonlyArray<function (type parameter) B in <A extends object, N extends string, B>(self: ReadonlyArray<A>, tag: Exclude<N, keyof A>, f: (a: NoInfer<A>) => ReadonlyArray<B>): Array<{ [K in N | keyof A]: K extends keyof A ? A[K] : B; }>B>
): interface Array<T>Array<{ [function (type parameter) KK in function (type parameter) N in <A extends object, N extends string, B>(self: ReadonlyArray<A>, tag: Exclude<N, keyof A>, f: (a: NoInfer<A>) => ReadonlyArray<B>): Array<{ [K in N | keyof A]: K extends keyof A ? A[K] : B; }>N | keyof function (type parameter) A in <A extends object, N extends string, B>(self: ReadonlyArray<A>, tag: Exclude<N, keyof A>, f: (a: NoInfer<A>) => ReadonlyArray<B>): Array<{ [K in N | keyof A]: K extends keyof A ? A[K] : B; }>A]: function (type parameter) KK extends keyof function (type parameter) A in <A extends object, N extends string, B>(self: ReadonlyArray<A>, tag: Exclude<N, keyof A>, f: (a: NoInfer<A>) => ReadonlyArray<B>): Array<{ [K in N | keyof A]: K extends keyof A ? A[K] : B; }>A ? function (type parameter) A in <A extends object, N extends string, B>(self: ReadonlyArray<A>, tag: Exclude<N, keyof A>, f: (a: NoInfer<A>) => ReadonlyArray<B>): Array<{ [K in N | keyof A]: K extends keyof A ? A[K] : B; }>A[function (type parameter) KK] : function (type parameter) B in <A extends object, N extends string, B>(self: ReadonlyArray<A>, tag: Exclude<N, keyof A>, f: (a: NoInfer<A>) => ReadonlyArray<B>): Array<{ [K in N | keyof A]: K extends keyof A ? A[K] : B; }>B }>
} = import internalDoNotationinternalDoNotation.const bind: <F extends TypeLambda>(
map: Map<F>,
flatMap: FlatMap<F>
) => {
<
N extends string,
A extends object,
R2,
O2,
E2,
B
>(
name: Exclude<N, keyof A>,
f: (a: NoInfer<A>) => Kind<F, R2, O2, E2, B>
): <R1, O1, E1>(
self: Kind<F, R1, O1, E1, A>
) => Kind<
F,
R1 & R2,
O1 | O2,
E1 | E2,
{
[K in keyof A | N]: K extends keyof A
? A[K]
: B
}
>
<
R1,
O1,
E1,
A extends object,
N extends string,
R2,
O2,
E2,
B
>(
self: Kind<F, R1, O1, E1, A>,
name: Exclude<N, keyof A>,
f: (a: NoInfer<A>) => Kind<F, R2, O2, E2, B>
): Kind<
F,
R1 & R2,
O1 | O2,
E1 | E2,
{
[K in keyof A | N]: K extends keyof A
? A[K]
: B
}
>
}
bind<ReadonlyArrayTypeLambda>(const map: {
<S extends ReadonlyArray<any>, B>(
f: (a: ReadonlyArray.Infer<S>, i: number) => B
): (self: S) => ReadonlyArray.With<S, B>
<S extends ReadonlyArray<any>, B>(
self: S,
f: (a: ReadonlyArray.Infer<S>, i: number) => B
): ReadonlyArray.With<S, B>
}
Transforms each element using a function, returning a new array.
When to use
Use to transform each element independently while preserving the array shape.
Details
The function receives (element, index). The return type preserves
NonEmptyArray.
Example (Doubling values)
import { Array } from "effect"
console.log(Array.map([1, 2, 3], (x) => x * 2)) // [2, 4, 6]
map, const flatMap: {
<
S extends ReadonlyArray<any>,
T extends ReadonlyArray<any>
>(
f: (a: ReadonlyArray.Infer<S>, i: number) => T
): (
self: S
) => ReadonlyArray.AndNonEmpty<
S,
T,
ReadonlyArray.Infer<T>
>
<A, B>(
self: NonEmptyReadonlyArray<A>,
f: (
a: A,
i: number
) => NonEmptyReadonlyArray<B>
): NonEmptyArray<B>
<A, B>(
self: ReadonlyArray<A>,
f: (a: A, i: number) => ReadonlyArray<B>
): Array<B>
}
Maps each element to an array and flattens the results into a single array.
When to use
Use to map each array element to zero or more values and concatenate the
results in one pass.
Details
The function receives (element, index). This returns NonEmptyArray when
both the input and mapped arrays are non-empty.
Example (Flat mapping an array)
import { Array } from "effect"
console.log(Array.flatMap([1, 2, 3], (x) => [x, x * 2])) // [1, 2, 2, 4, 3, 6]
flatMap) as any