import * as fun from "https://deno.land/x/fun@v.2.0.0-alpha.11/option.ts";
The Option type is generally considered functional programming's response to handling null or undefined. Sometimes Option is also called Maybe. Its purpose is to represent the possibility that some data is not available.
Variables
The canonical implementation of Alt for Option. It contains the methods alt and map | |
The canonical implementation of Applicative for Option. It contains the methods of, ap, and map. | |
The canonical implementation of Apply for Option. It contains the methods ap and map. | |
The canonical implementation of Chain for Option. It contains the methods ap, map, and chain. | |
The canonical implementation of Extend for Option. It contains the methods map and extend | |
The canonical implementation of Filterable for Option. It contains the methods filter, filterMap, partition, and partitionMap. | |
The canonical implementation of Foldable for Option. It contains the method reduce. | |
The canonical implementation of Functor for Option. It contains the method map. | |
The canonical implementation of Monad for Option. It contains the methods of, ap, map, join, and chain. | |
v none | 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 canonical implementation of Traversable for Option. It contains the methods map, reduce, and traverse. |
Functions
f alt | Replace an first with second if first is None. This allows one to offer a a replacement or default. |
f ap | Apply a value A wrapped in an option to a function (a: A) => I wrapped in an Option. If either the wrapped value or the wrapped function are None then the result is None, if they are both Some then the result is Some. |
Apply a function (a: A) => Option to the wrapped value of an Option if the wrapped value exists, flattening the application result into an Option. This is the equivalent of first mapping from Option to Option<Option> and then calling join to flatten the Options. | |
The constNone is a thunk that returns the canonical none instance. | |
Returns none, always. This is the empty function used by getMonoid. | |
Apply a predicate to the inner value of an Option, returning true if the option is Some and the predicate returns true, otherwise returning false. | |
Extend an Option by mapping it to a concrete value. | |
Apply a refinement or predicate to the inner value of an Option, returning the original option if the value exists and the predicate/refinement return true, otherwise returning None. | |
Apply a filter and mapping operation at the same time against an Option. This is equivalent to the chain function for Option. | |
The fromNullable function takes a potentially null or undefined value and maps null or undefined to None and non-null and non-undefined values to Some<NonNullable>. | |
The fromPredicate function will test the value a with the predicate. If the predicate evaluates to false then the function will return a None, otherwise it will return the value wrapped in Some. | |
Create an instance of Eq<Option> given an instance of Eq. | |
Create an instance of Monoid<Option> given an instance of Monoid. | |
Create an instance of Ord<Option> given an instance of Ord. | |
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. | |
Create an instance of Semigroup<Option> given an instance of Semigroup. | |
Create an instance of Show for Option given an instance of Show for A. | |
Tests wether an Option is None, returning true if the passed option is None and false if it is Some. | |
Tests wether an Option is Some, returning true if the passed option is Some and false if it is None. | |
f join | Flatten a nested Option<Option> into an Option. |
f map | Apply the mapping function fai to the inner value of an Option if it exists. If the option is None then this function does nothing. |
Apply a mapping function to an Option but if the mapping function returns null or undefined the null or undefined value is lifted into None. | |
The match functionis 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. | |
f of | Create an Option by wrapping any value A in Some. |
Given a refinement or predicate, return a function that splits an Option into a Pair<Option, Option>. Due to the nature of the option type this will always return Pair<Some, None>, Pair<None, None>, or Pair<None, Some>. | |
Map and partition over the inner value of an Option at the same time. If the option passed is None then the result is [None, None], otherwise Right will result in [Some, None], and Left will result in [None, Some]. | |
Reduce over an Option. Since an Option contains at most one value this function operates a lot like getOrElse. If the passed option is None then it returns the initial value, otherwise the reducer function is called with both the initial value and the inner A. | |
f some | 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. | |
Traverse over an Option using the supplied Applicative. This allows one to turn an Option into Kind<V, Option>. | |
Take a function that can throw and wrap it in a try/catch block. Returns a new function that takes the same arguments as the original but returns the original value wrapped in an Option. If the function throws then the new function returns None, otherwise it returns Some. |
Interfaces
Specifies Option as a Higher Kinded Type, with covariant parameter A corresponding to the 0th index of any substitutions. |
Type Aliases
T None | 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. | |
T Some | The Some type represents the existence of a value. |