effect-io-ai

Package: effect
Module: Optic

Optic.Lens

Focuses on exactly one part A inside a whole S.

When to use

Use when you always have a value to read and need the original S to produce the updated whole, unlike Iso.

Details

Example (Focusing on a struct field)

import { Optic } from "effect"

type Person = { readonly name: string; readonly age: number }

const _name = Optic.id<Person>().key("name")

console.log(_name.get({ name: "Alice", age: 30 }))
// Output: "Alice"

See

Signature

export interface Lens<in out S, in out A> extends Optional<S, A> {
  readonly get: (s: S) => A
}

Source

Since v4.0.0