An open API service indexing awesome lists of open source software.

https://github.com/m1kc3b/explicitly

A TypeScript library inspired by Rust’s Option<T> and Result<T, E>, providing safe and expressive error handling. Avoid null, undefined, and exceptions with explicit, functional-style handling of missing values and errors. 🚀
https://github.com/m1kc3b/explicitly

error-handling functional-programming monad no-exception safe-types typescript

Last synced: 8 months ago
JSON representation

A TypeScript library inspired by Rust’s Option<T> and Result<T, E>, providing safe and expressive error handling. Avoid null, undefined, and exceptions with explicit, functional-style handling of missing values and errors. 🚀

Awesome Lists containing this project

README

          

# Explicitly

`Explicitly` is a TypeScript library inspired by Rust that introduces Option and Result. These types eliminate null, undefined, and unexpected exceptions by enforcing explicit handling of missing values and errors. With a functional approach, explicit enhances code robustness and readability while offering intuitive methods such as unwrapOr(), map(), and isOk().

Whether you're dealing with uncertain data, handling API errors, or preventing crashes due to missing values, `Explicitly` provides a safe and elegant alternative to traditional error-handling practices in JavaScript and TypeScript.

This library implements two generic types:
- Option\: stands for a real that can exist (Some\) or be absent (None).
- Result: stands for either a successful value (Ok\) or an error (Err\).

## `Option`

It is a safer alternative to null (the billion-dollar mistake) and undefined.

None, represents the absence of a value and forces the developer to handle this case explicitly.

Some\ contains a value and provides method to handle it.

## `Result`

It is an alternative to `throw new Error()` and involve to handle errors explicitly.

Ok\ contains a successfull value, and provides methods to handle it.

Err\ contains an error and prevents use without verification.