Skip to main content
Module

x/fun/mod.ts>optics.view

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

A pipeable view function that applies a value S to a Viewer<S, A>. It will return either a raw value, an option, or a readonlyarray based on the tag of the Viewer. Note: All Optics are Viewers.

Examples

Example 1

import * as O from "./optics.ts";
import { pipe } from "./fn.ts";

type Foo = { readonly bar: number };

const bar = pipe(O.id<Foo>(), O.prop("bar"));

const result = pipe(bar, O.view({ bar: 1 })); // 1

Returns

<U extends Tag, A>(viewer: Viewer<U, S, A>) => ReturnType<viewer.view>