Skip to main content
Module

x/fun/mod.ts>optic.left

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

A preconstructed composed prism that focuses on the Left value of an Either.

Examples

Example 1

import * as O from "./optic.ts";
import * as E from "./either.ts";
import { pipe } from "./fn.ts";

type Response = E.Either<Error, string>;

const value = pipe(O.id<Response>(), O.left);

const result1 = pipe(value, O.view(E.right("Good job!")));
// None
const result2 = pipe(value, O.view(E.left(new Error("Something broke"))));
// Some(Error("Something broke"))

type

<U extends Tag, S, B, A>(optic: Optic<U, S, Either<B, A>>) => Optic<Align<U, AffineTag>, S, B>