Hyperlinkv0.8.0-beta.28

Optic

Optic.makeIsofunctioneffect/Optic.ts:104
<S, A>(get: (s: S) => A, set: (a: A) => S): Iso<S, A>

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 }
constructorsIsoid
Source effect/Optic.ts:1043 lines
export function makeIso<S, A>(get: (s: S) => A, set: (a: A) => S): Iso<S, A> {
  return make(new IsoNode(get, set))
}
Referenced by 2 symbols