Package: effect
Module: Optic
A lossless, reversible conversion between types S and A.
When to use
Use when you have a pair of functions that convert back and forth without losing
information (e.g. Record ↔ entries, Celsius ↔ Fahrenheit).
Details
get(s) always succeeds and returns an A.set(a) always succeeds and returns an S.get(set(a)) === a and set(get(s)) equals s (round-trip laws).Lens and Prism.Example (Converting between Celsius and Fahrenheit)
import { Optic } from "effect"
const fahrenheit = Optic.makeIso<number, number>(
(c) => c * 9 / 5 + 32,
(f) => (f - 32) * 5 / 9
)
console.log(fahrenheit.get(100))
// Output: 212
console.log(fahrenheit.set(32))
// Output: 0
See
makeIso — constructorLens — when you only need a one-directional focus into a wholePrism — when the focus may not be presentSignature
export interface Iso<in out S, in out A> extends Lens<S, A>, Prism<S, A> {}
Since v4.0.0