minifunc

Result

A Result is a type that represents either success or failure. It is similar to rust’s Result type.

Initialization

import { Result, Ok, Err } from 'minifunc';

const ok = Ok(1);
const err = Err('error');

Notes

API

Result<T, E>

interface Result<T, E> {
	isOk(): boolean;
	isErr(): boolean;
	unwrap(): T;
	unwrapOr(value: T): T;
	unwrapOrElse(fn: (error: E) => T): T;
	unwrapUnchecked(): T;
	map<U>(fn: (value: T) => U): Result<U, E>;
	mapErr<U>(fn: (error: E) => U): Result<T, U>;
}

Ok(..) and Err(..)

Both are exported type aliases for Result.Ok and Result.Err respectively.