<S extends Constraint>(_: S): Optic_.Iso<S["Iso"], S["Iso"]>Returns an identity Iso over the schema's focus (Iso) side.
Optic
Source effect/Schema.ts:139913 lines
export function function toIsoFocus<S extends Constraint>(
_: S
): Optic_.Iso<S["Iso"], S["Iso"]>
Returns an identity Iso over the schema's focus (Iso) side.
toIsoFocus<function (type parameter) S in toIsoFocus<S extends Constraint>(_: S): Optic_.Iso<S["Iso"], S["Iso"]>S extends Constraint>(_: S extends Constraint_: function (type parameter) S in toIsoFocus<S extends Constraint>(_: S): Optic_.Iso<S["Iso"], S["Iso"]>S): import Optic_Optic_.interface Iso<in out S, in out A>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).
- You want the strongest optic that can be composed with any other.
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).
- Extends both
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
Iso<function (type parameter) S in toIsoFocus<S extends Constraint>(_: S): Optic_.Iso<S["Iso"], S["Iso"]>S["Iso"], function (type parameter) S in toIsoFocus<S extends Constraint>(_: S): Optic_.Iso<S["Iso"], S["Iso"]>S["Iso"]> {
return import Optic_Optic_.function id<S>(): Iso<S, S>Iso that focuses on the whole value unchanged.
When to use
Use when you need to start an optic chain with a focus on the whole value.
Details
get(s) returns s.
set(a) returns a.
- Singleton — every call returns the same instance.
Example (Starting an optic chain)
import { Optic } from "effect"
type S = { readonly x: number }
const _x = Optic.id<S>().key("x")
console.log(_x.get({ x: 42 }))
// Output: 42
id()
}