Skip to main content
Module

x/ahh/mod.ts>O

Idiomatic type-safety functions.
Go to Latest
class O
Re-export
import { O } from "https://deno.land/x/ahh@v0.10.3/mod.ts";

Functionality for Option.

Static Methods

and<T, U>(opt: Option<T>, other: Option<U>): Option<U>

Return other if opt is Some, or None.

contains<T>(opt: Option<T>, value: T): boolean

Returns whether opt strictly equals value, or false if it is a None.

filter<T>(opt: Option<T>, f: (_: T) => boolean): Option<T>

Calls f with opt, and returns it if the result is true.

inspect<T>(opt: Option<T>, f: (_: T) => unknown): Option<T>

Calls f with opt, and returns the original opt.

isNone<T>(opt: Option<T>): opt is None

Returns whether opt is a None.

isSome<T>(opt: Option<T>): opt is Some<T>

Returns whether opt is a Some.

map<T, U>(opt: Option<T>, f: (_: T) => U): Option<U>

Calls f with opt, and returns the result.

okOr<T, E extends Error>(opt: Option<T>, err: E): Result<T, E>

Converts opt into an Ok if it is a Some.

or<T>(opt: Option<T>, other: Option<T>): Option<T>

Return opt if it is a Some, or other.

unwrap<T>(opt: Option<T>): opt extends Some<T> ? T : never

Returns opt if it is a Some, or throws.

unwrapOr<T>(opt: Option<T>, default_: T): T

Returns opt if it is a Some, or returns default_.