Skip to main content

@neoangelism/tsrs@0.0.2

latest

tsrs - a typescript library that emulates rust's Result and Option types

Works with
This package works with Bun
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Browsers
JSR Score
94%
Published
3 weeks ago
indexOption
class Option
deno add @neoangelism/tsrs
import { Option } from "@neoangelism/tsrs";
npx jsr add @neoangelism/tsrs
import { Option } from "@neoangelism/tsrs";
yarn dlx jsr add @neoangelism/tsrs
import { Option } from "@neoangelism/tsrs";
pnpm dlx jsr add @neoangelism/tsrs
import { Option } from "@neoangelism/tsrs";
bunx jsr add @neoangelism/tsrs
import { Option } from "@neoangelism/tsrs";

Represents an optional value

Constructors

new
Option(t: None | Some<T>)

Constructs a new Option instance.

Type Parameters

Methods

expect(message: string): T

Unwraps the Some value or throws an error with a custom message.

Checks if the option is None.

Checks if the option is Some.

Unwraps the Some value.

unwrapOr(value: T): T

Unwraps the Some value or returns a fallback value.

unwrapOrElse(cb: () => T): T

Unwraps the Some value or computes a fallback value by invoking a function.

Static Properties

none: None

Represents a None value

some: <T>(value: T) => Some<T>

Constructs a Some value.

Static Methods

fromResult<U, E>(result: Result<U, E>): Option<U>

Creates an Option from a Result.

fromThrow<T>(fn: () => T): Option<T>

Creates an Option from a function that can throw.