Hyperlinkv0.8.0-beta.28

Newtype

Newtype.makeIsofunctioneffect/Newtype.ts:177
<N extends Newtype.Any>(): Optic.Iso<N, Newtype.Carrier<N>>

Creates an Optic.Iso for a newtype, providing both wrapping (set) and unwrapping (get).

When to use

Use as the primary way to construct and deconstruct newtype values.

Details

The returned iso composes with other optics via the standard Optic API. Both directions have zero runtime cost because they are identity casts.

Example (Wrapping and unwrapping with an iso)

import { Newtype } from "effect"

interface Label extends Newtype.Newtype<"Label", string> {}

const labelIso = Newtype.makeIso<Label>()

const label: Label = labelIso.set("world")
const str: string = labelIso.get(label) // "world"
constructorsvalue
Source effect/Newtype.ts:1773 lines
export function makeIso<N extends Newtype.Any>(): Optic.Iso<N, Newtype.Carrier<N>> {
  return Optic.makeIso(value, cast)
}