o optics v2.0.0
Docs menu
API Types

Types

The package exports runtime factories and matching public types.

import {
  Lens,
  Prism,
  Iso,
  Traversal,
  Getter,
  Fold,
  type Optic,
  type InferSource,
  type InferTarget,
} from '@fuiste/optics'

Optic

Optic<S, A> is the union of every optic kind.

type Optic<S, A> =
  | Lens<S, A>
  | Prism<S, A>
  | Iso<S, A>
  | Traversal<S, A>
  | Getter<S, A>
  | Fold<S, A>

Use it when a function can accept any optic and branch on _tag.

InferSource

Extracts the source type from an optic.

type Source = InferSource<typeof nameLens>

InferTarget

Extracts the focused target type from an optic.

type Target = InferTarget<typeof nameLens>

Runtime Tags

Every optic has a _tag discriminator.

if (optic._tag === 'lens') {
  optic.get(source)
}

This is intentionally boring. Boring discriminants are a gift.