effect-io-ai

Package: effect
Module: Optic

Optic.makeIso

Creates an Iso from a pair of conversion functions.

When to use

Use when you have two pure conversion functions that preserve all information between S and A.

Details

The returned optic can be composed with any other optic.

Example (Wrapping and unwrapping a branded type)

import { Optic } from "effect"

type Meters = { readonly value: number }
const meters = Optic.makeIso<Meters, number>(
  (m) => m.value,
  (n) => ({ value: n })
)

console.log(meters.get({ value: 100 }))
// Output: 100

console.log(meters.set(42))
// Output: { value: 42 }

See

Signature

declare const makeIso: <S, A>(get: (s: S) => A, set: (a: A) => S) => Iso<S, A>

Source

Since v4.0.0