effect-io-ai

Package: effect
Module: Struct

Struct.map

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

Signature

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]>; }; }

Source

Since v4.0.0