Skip to main content
Module

x/fun/optics.ts>nilable

A collection of algebraic data types, lenses, and schemables based on a light weight higher kinded type implementation. Written for deno.
Go to Latest
variable nilable
import { nilable } from "https://deno.land/x/fun@v.2.0.0-alpha.11/optics.ts";

A preconstructed filter that focuses on the the non-null and non-undefined value of A | null | undefined.

Examples

Example 1

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

type Input = { value?: string | null };

const value = pipe(O.id<Input>(), O.prop("value"), O.nilable);

const result1 = pipe(value, O.view({})); // None
const result2 = pipe(value, O.view({ value: "Hello" })); // Some("Hello")

type

<U extends Tag, S, A>(first: Optic<U, S, A>) => Optic<Align<U, AffineTag>, S, NonNullable<A>>