Skip to main content
Module

x/hkts/option.ts

Functional programming tools: option, either, task, state, optics, etc.
Latest
import * as hkts from "https://deno.land/x/hkts@v0.0.52/option.ts";

Variables


Pipeables


constNone is a thunk that returns the canonical none instance.

fold is the standard catamorphism on an Option. It operates like a switch case operator over the two potential cases for an Option type. One supplies functions for handling the Some case and the None case with matching return types and fold calls the correct function for the given option.

fromNullable takes a potentially null or undefined value and maps null or undefined to None and non-null and non-undefined values to Some<NonNullable>

fromPredicate will test the value a with the predicate. If the predicate evaluates to false then the function will return a None, otherwise the value wrapped in Some


Modules


getOrElse operates like a simplified fold. One supplies a thunk that returns a default inner value of the Option for the cases where the option is None.

Generates a Setoid module for an option with inner type of A.

Generates a Show module for an option with inner type of A.

Tests wether an Option is None. Can be used as a predicate.

Tests wether an Option is Some. Can be used as a predicate.

mapNullable is useful for piping an option's values through functions that may return null or undefined.

The cannonical implementation of the None type. Since all None values are equivalent there is no reason to construct more than one object instance.

The some constructer takes any value and wraps it in the Some type.

toNullable returns either null or the inner value of an Option. This is useful for interacting with code that handles null but has no concept of the Option type.

toUndefined returns either undefined or the inner value of an Option. This is useful for interacting with code that handles undefined but has no concept of the Option type.

tryCatch takes a thunk that can potentially throw and wraps it in a try/catch statement. If the thunk throws then tryCatch returns None, otherwise it returns the result of the thunk wrapped in a Some.


Kind Registration


Type Aliases

The None type represents the non-existence of a value.

The Option represents a type A that may or may not exist. It's the functional progamming equivalent of A | undefined | null.

The Some type represents the existence of a value.