Skip to main content
Module

x/funky/mod.ts>Option

Getting funky with Deno!
Latest
interface Option
import { type Option } from "https://deno.land/x/funky@v0.3.2/mod.ts";

Represents a runtime-safe value which is optional. An optional value is a value which might or might not be present. The Option type allows you to write safe code around that value, without unexpected runtime exceptions.

Properties

readonly
_type: OptionType
readonly
isSome: boolean

Indicates whether the option is an OptionSome instance.

readonly
isNone: boolean

Indicates whether the option is an OptionNone instance.

Methods

map<U>(handler: (value: T) => U): Option<U>

If the option is an OptionSome instance invokes the @handler function, providing the wrapped value as the argument and returns the result as an Option. Otherwise, returns an OptionNone instance.

match<U>(handler: OptionMatch<T, U>): U

If the option is an OptionSome instance invokes the @handler.some function, providing the wrapped value as the argument and returns the result.

Otherwise, invokes the @handler.none function and returns the result.

matchSome(handler: (value: T) => void): void

If the option is an OptionSome instance invokes the @handler function, providing the wrapped value as the argument.

matchNone(handler: () => void): void

If the option is an OptionSome instance invokes the @handler function. Otherwise, the @handler function is not invoked.

or<U>(other: Option<U>): Option<T | U>

If the option is an OptionNone instance returns the specified @other option. Otherwise, returns the original OptionSome instance.

and<U>(other: Option<U>): Option<U>

If the option is an OptionSome instance returns the specfied @other option. Otherwise, returns an OptionNone instance.

andThen<U>(handler: (value: T) => Option<U>): Option<U>

If the option is an OptionSome instance invokes the @handler function, providing the wrapped value as the argument and returns the result. Otherwise, returns an OptionNone instance.

unwrap(): T | never

If the option is an OptionSome instance returns the wrapped value. Otherwise, throws an Error.

unwrapOr(def: T): T

If the option is an OptionNone instance returns the specified @def value. Otherwise, returns the original wrapped value.