Package: effect
Module: Struct
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] }
See
mapPick – apply a lambda only to selected keysmapOmit – apply a lambda to all keys except selected onesevolve – apply different functions to different keysSignature
declare 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]>; }; }
Since v4.0.0