Skip to main content
Module

x/funky/mod.ts>Result

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

Represents a runtime-safe result of an operation. The operation might be successful, in which case a Result instance wrapping the produced value of type T is returned. Otherwise, when the operation fails a Result instance wrapping the error of type E is returned.

Properties

readonly
_type: ResultType
readonly
isOk: boolean

Indicates whether the result is a ResultOk instance.

readonly
isErr: boolean

Indicates whether the result is a ResultErr instance.

Methods

map<U>(handler: (value: T) => U): Result<U, E>

If the result is a ResultOk instance invokes the @handler function, providing the wrapped value as the argument and returns the result. Otherwise, returns the original ResultErr instance.

match<U>(handler: ResultMatch<T, E, U>): U

If the result is a ResultOk instance invokes the @handler.ok function, providing the wrapped value as the argument and returns the result.

Otherwise, invokes the @handler.err function, providing the wrapped error as the argument and returns the result.

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

If the result is a ResultOk instance invokes the @handler function, providing the wrapped value as the argument.

matchErr(handler: (error: E) => void): void

If the result is a ResultErr instance invokes the @handler function, providing the wrapped error as the argument.

unwrap(): T | never

If the result is a ResultOk instance returns the wrapped value. Otherwise, throws an Error.

unwrapOr(def: T): T

If the result is a ResultErr instance returns the specified @def value. Otherwise, returns the original wrapped value.

unwrapErr(): E | never

If the result is a ResultErr instance returns the wrapped error. Otherwise, throws an Error.

andThen<U>(handler: (value: T) => Result<U, E>): Result<U, E>

If the result is a ResultOk instance invokes the @handler function, providing the wrapped value as the argument and returns the result. Otherwise, returns the original ResultErr instance.

orElse<U>(handler: (error: E) => Result<U, E>): Result<T | U, E>

If the result is a ResultErr instance invokes the @handler function, providing the wrapped error as the argument and returns the result. Otherwise, returns the original ResultOk instance.