Skip to content

hnatiukr/unwrap-or

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Warning

The unwrap-or library has moved off Github.

The canonical Git repository is located at https://codeberg.org/hnatiukr/unwrap-or.

There is a mirror of the repository at https://github.com/hnatiukr/unwrap-or.

Unwrap OR

A TypeScript implementation of Rust's Option and Result types.

no deps | tree-shakeable | side-effect free

version score

It is a playground library that closely mirrors Rust's Option and Result API. While created primarily for fun and learning, it's robust enough for real-world applications. It allows for safer, more expressive handling of optional values through a monadic interface. Snake_case is used for the plausibility of the original.

Use it to:

  • eliminate null checks
  • make optional logic explicit
  • chain transformations on values that might not exist
  • handle errors gracefully

The name unwrap-or is a reference to the unwrap_or method in the Option/Result types and a combination of the first letters "-OR" of two monads for Option and Result types. It also relfects the logical OR operation reflecting two possible states.

Installation

Via deno:

deno add jsr:@lab/unwrap-or

You can also use your favorite package manager:

# pnpm
pnpm i jsr:@lab/unwrap-or

# npm
npx jsr add @lab/unwrap-or

# bun
bunx jsr add @lab/unwrap-or

# yarn
yarn add jsr:@lab/unwrap-or

Overview

See the documentation for unwrap-or usage, module specifications and API/methods details:

Inspirations

  • fnts - minimal functional programming utilities for TypeScript & JavaScript inspired by the programming language Haskell.

  • ts-expression - pair constructor, binary representation, a minimal implementation of Lisp's symbolic expressions (s-expressions) for TypeScript.

License

Made by a human being, not LLM.

Copyright © 2025 Roman Hnatiuk

Licensed under MIT.

About

A TypeScript implementation of Rust's Option and Result types.

Resources

License

Stars

Watchers

Forks