Skip to main content
Module

x/fun/mod.ts>optic._unsafeCast

A collection of algebraic data types, lenses, and schemables based on a light weight higher kinded type implementation. Written for deno.
Latest
function optic._unsafeCast
import { optic } from "https://deno.land/x/fun@v2.0.0/mod.ts";
const { _unsafeCast } = optic;

Given a Viewer<U, S, A> and an optic tag V, this function produces a view function that can be used in a Viewer<V, S, A>. However, not all casts are valid. The following are the only supported casts, by their optic tag:

  • LensTag => LensTag
  • LensTag => AffineTag
  • LensTag => FoldTag
  • AffineTag => AffineTag
  • AffineTag => FoldTag
  • FoldTag => FoldTag

The following are unsupported casts which will throw at runtime:

  • AffineTag => LensTag
  • FoldTag => AffineTag
  • FoldTag => LensTag

This library has no code that leads to unsupported casts, but if one wishes to extend its functionality by replicating the cast logic, these cases must be considered.

Type Parameters

U extends Tag
V extends Tag
S
A

Parameters

viewer: Viewer<U, S, A>
tag: V

Returns

Viewer<V, S, A>["view"]