<L extends Lambda>(lambda: L): <S extends object>(
self: S
) => { [K in keyof S]: Apply<L, S[K]> }
<S extends object, L extends Lambda>(self: S, lambda: L): {
[K in keyof S]: Apply<L, S[K]>
}Applies a Lambda transformation to every value in a struct.
When to use
Use when you want to apply the same function to every value in a struct.
Details
The lambda must be created with lambda so the compiler can track the output types.
Example (Wrapping every value in an array)
import { pipe, Struct } from "effect"
interface AsArray extends Struct.Lambda {
<A>(self: A): Array<A>
readonly "~lambda.out": Array<this["~lambda.in"]>
}
const asArray = Struct.lambda<AsArray>((a) => [a])
const result = pipe({ width: 10, height: 20 }, Struct.map(asArray))
console.log(result) // { width: [10], height: [20] }export const const map: {
<L extends Lambda>(lambda: L): <
S extends object
>(
self: S
) => {
[K in keyof S]: Apply<L, S[K]>
}
<S extends object, L extends Lambda>(
self: S,
lambda: L
): {
[K in keyof S]: Apply<L, S[K]>
}
}
Applies a
Lambda
transformation to every value in a struct.
When to use
Use when you want to apply the same function to every value in a struct.
Details
The lambda must be created with
lambda
so the compiler can track the
output types.
Example (Wrapping every value in an array)
import { pipe, Struct } from "effect"
interface AsArray extends Struct.Lambda {
<A>(self: A): Array<A>
readonly "~lambda.out": Array<this["~lambda.in"]>
}
const asArray = Struct.lambda<AsArray>((a) => [a])
const result = pipe({ width: 10, height: 20 }, Struct.map(asArray))
console.log(result) // { width: [10], height: [20] }
map: {
<function (type parameter) L in <L extends Lambda>(lambda: L): <S extends object>(self: S) => { [K in keyof S]: Apply<L, S[K]>; }L extends Lambda>(
lambda: L extends Lambdalambda: function (type parameter) L in <L extends Lambda>(lambda: L): <S extends object>(self: S) => { [K in keyof S]: Apply<L, S[K]>; }L
): <function (type parameter) S in <S extends object>(self: S): { [K in keyof S]: Apply<L, S[K]>; }S extends object>(self: S extends objectself: function (type parameter) S in <S extends object>(self: S): { [K in keyof S]: Apply<L, S[K]>; }S) => { [function (type parameter) KK in keyof function (type parameter) S in <S extends object>(self: S): { [K in keyof S]: Apply<L, S[K]>; }S]: type Apply<L extends Lambda, V> = (L & {
readonly "~lambda.in": V
})["~lambda.out"]
Applies a
Lambda
type-level function to a value type V, producing
the output type.
When to use
Use when you need to compute what type a Lambda would produce for a
given input.
Details
This works by intersecting the Lambda with { "~lambda.in": V } and reading
"~lambda.out".
Example (Computing the output type of a lambda)
import type { Struct } from "effect"
interface ToString extends Struct.Lambda {
readonly "~lambda.out": string
}
// Result is `string`
type Result = Struct.Apply<ToString, number>
Apply<function (type parameter) L in <L extends Lambda>(lambda: L): <S extends object>(self: S) => { [K in keyof S]: Apply<L, S[K]>; }L, function (type parameter) S in <S extends object>(self: S): { [K in keyof S]: Apply<L, S[K]>; }S[function (type parameter) KK]> }
<function (type parameter) S in <S extends object, L extends Lambda>(self: S, lambda: L): { [K in keyof S]: Apply<L, S[K]>; }S extends object, function (type parameter) L in <S extends object, L extends Lambda>(self: S, lambda: L): { [K in keyof S]: Apply<L, S[K]>; }L extends Lambda>(
self: S extends objectself: function (type parameter) S in <S extends object, L extends Lambda>(self: S, lambda: L): { [K in keyof S]: Apply<L, S[K]>; }S,
lambda: L extends Lambdalambda: function (type parameter) L in <S extends object, L extends Lambda>(self: S, lambda: L): { [K in keyof S]: Apply<L, S[K]>; }L
): { [function (type parameter) KK in keyof function (type parameter) S in <S extends object, L extends Lambda>(self: S, lambda: L): { [K in keyof S]: Apply<L, S[K]>; }S]: type Apply<L extends Lambda, V> = (L & {
readonly "~lambda.in": V
})["~lambda.out"]
Applies a
Lambda
type-level function to a value type V, producing
the output type.
When to use
Use when you need to compute what type a Lambda would produce for a
given input.
Details
This works by intersecting the Lambda with { "~lambda.in": V } and reading
"~lambda.out".
Example (Computing the output type of a lambda)
import type { Struct } from "effect"
interface ToString extends Struct.Lambda {
readonly "~lambda.out": string
}
// Result is `string`
type Result = Struct.Apply<ToString, number>
Apply<function (type parameter) L in <S extends object, L extends Lambda>(self: S, lambda: L): { [K in keyof S]: Apply<L, S[K]>; }L, function (type parameter) S in <S extends object, L extends Lambda>(self: S, lambda: L): { [K in keyof S]: Apply<L, S[K]>; }S[function (type parameter) KK]> }
} = import dualdual(
2,
<function (type parameter) S in <S extends object, L extends Function>(self: S, lambda: L): anyS extends object, function (type parameter) L in <S extends object, L extends Function>(self: S, lambda: L): anyL extends Function>(self: S extends objectself: function (type parameter) S in <S extends object, L extends Function>(self: S, lambda: L): anyS, lambda: L extends Functionlambda: function (type parameter) L in <S extends object, L extends Function>(self: S, lambda: L): anyL) => {
return function buildStruct<S, (k: keyof S, v: S[keyof S]) => [keyof S, any]>(source: S, f: (k: keyof S, v: S[keyof S]) => [keyof S, any]): anyWalk source; for each key decide what to emit via the small callback.
The callback returns either
• undefined → nothing is copied, or
• [newKey, newVal]
so every public API just supplies a different callback.
buildStruct(self: S extends objectself, (k: keyof Sk, v: S[keyof S]v) => [k: keyof Sk, lambda: L extends Functionlambda(v: S[keyof S]v)])
}
)