<L extends (a: any) => any>(f: (a: Parameters<L>[0]) => ReturnType<L>): LWraps a plain function as a Lambda value so it can be used with map, mapPick, and mapOmit.
When to use
Use to create a typed lambda for struct mapping APIs that need type-level input and output tracking.
Details
The type parameter L encodes both the input and output types at the type
level, allowing the compiler to track how struct value types change. At
runtime, the returned value is the same function; lambda only adjusts the
type.
Example (Wrapping values in arrays)
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({ x: 1, y: "hello" }, Struct.map(asArray))
console.log(result) // { x: [1], y: ["hello"] }export const const lambda: <L extends (a: any) => any>(
f: (a: Parameters<L>[0]) => ReturnType<L>
) => L
Wraps a plain function as a
Lambda
value so it can be used with
When to use
Use to create a typed lambda for struct mapping APIs that need type-level
input and output tracking.
Details
The type parameter L encodes both the input and output types at the type
level, allowing the compiler to track how struct value types change. At
runtime, the returned value is the same function; lambda only adjusts the
type.
Example (Wrapping values in arrays)
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({ x: 1, y: "hello" }, Struct.map(asArray))
console.log(result) // { x: [1], y: ["hello"] }
lambda = <function (type parameter) L in <L extends (a: any) => any>(f: (a: Parameters<L>[0]) => ReturnType<L>): LL extends (a: anya: any) => any>(
f: (a: Parameters<L>[0]) => ReturnType<L>f: (a: Parameters<L>[0]a: type Parameters<
T extends (...args: any) => any
> = T extends (...args: infer P) => any
? P
: never
Obtain the parameters of a function type in a tuple
Parameters<function (type parameter) L in <L extends (a: any) => any>(f: (a: Parameters<L>[0]) => ReturnType<L>): LL>[0]) => type ReturnType<
T extends (...args: any) => any
> = T extends (...args: any) => infer R ? R : any
Obtain the return type of a function type
ReturnType<function (type parameter) L in <L extends (a: any) => any>(f: (a: Parameters<L>[0]) => ReturnType<L>): LL>
): function (type parameter) L in <L extends (a: any) => any>(f: (a: Parameters<L>[0]) => ReturnType<L>): LL => f: (a: Parameters<L>[0]) => ReturnType<L>f as any