effect-io-ai

Package: effect
Module: Optic

Optic.Iso

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

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

Signature

export interface Iso<in out S, in out A> extends Lens<S, A>, Prism<S, A> {}

Source

Since v4.0.0