Skip to main content
Module

x/ahh/mod.ts>R

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

Functionality for Result.

Static Methods

and<T, U, E extends Error>(res: Result<T, E>, other: Result<U, E>): Result<U, E>

Return other if res is Ok, or res.

contains<T, E extends Error>(res: Result<T, E>, value: T): boolean

Returns whether res strictly equals value, or false if it is an Err.

containsErr<T, E extends Error>(res: Result<T, E>, value: E): boolean

Returns whether res strictly equals value, or false if it is an Ok.

This only checks whether res and value have the same name and message.

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

Converts res into a Some if it is an Err.

fn<T, E extends Error>(f: () => T): Result<T, E>

Calls f and returns the result as an Ok, or returns an Err if it throws.

inspect<T, E extends Error>(res: Result<T, E>, f: (_: T) => unknown): Result<T, E>

Calls f with res, and returns the original res.

inspectErr<T, E extends Error>(res: Result<T, E>, f: (_: E) => unknown): Result<T, E>

Calls f with res, and returns the original res.

isErr<T, E extends Error>(res: Result<T, E>): res is Err<E>

Returns whether res is an Err.

isOk<T, E extends Error>(res: Result<T, E>): res is Ok<T>

Returns whether res is an Ok.

map<T, U, E extends Error>(res: Result<T, E>, f: (_: T) => U): Result<U, E>

Calls f with res, and returns the result.

mapErr<T, E extends Error, F extends Error>(res: Result<T, E>, f: (_: E) => F): Result<T, F>

Calls f with res, and returns the result.

ok<T, E extends Error>(res: Result<T, E>): Option<T>

Converts res into a Some if it is an Ok.

or<T, E extends Error, F extends Error>(res: Result<T, E>, other: Result<T, F>): Result<T, F>

Return res if it is an Ok, or other.

unwrap<T, E extends Error>(res: Result<T, E>): res extends Ok<T> ? T : never

Returns res if it is an Ok, or throws.

unwrapOr<T, E extends Error>(res: Result<T, E>, default_: T): T

Returns res if it is an Ok, or returns default_.