Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/OliverBrotchie/optionals

Rust-like error handling and options for TypeScript and Deno!
https://github.com/OliverBrotchie/optionals

deno error-handling rust typescript

Last synced: about 1 month ago
JSON representation

Rust-like error handling and options for TypeScript and Deno!

Awesome Lists containing this project

README

        

Optionals

Rust-like error handling and options for TypeScript, Node and Deno!

This module allows you to remove `null` and `undefined` from your projects with the help of ES6 Symbols and helper methods. Inspired by Rust's `Option`, `Result` enums.

## Why should you use Optionals?

The standard practice of returning `null` or `undefined` when no other value can be returned means that there is no simple way to express the difference between a function that has returned "nothing" and a `null` return type. There are also no easy ways to handle errors in a functional pattern. Rust's implementation of `Option` and `Result` guarantees correctness by expressly forcing correct result-handling practices.

This module provides a minimal, fast and simple way to create expressive functions and perform better pattern matching on resulting values! 🚀

## Usage

```ts
// Result
import { Result, Ok, Err } from "https://deno.land/x/[email protected]`/mod.ts";

// Option
import {
Option,
Some,
None,
} from "https://deno.land/x/[email protected]/mod.ts";
```

## Documentation

Please find further documentation on the [doc](https://doc.deno.land/https://deno.land/x/[email protected]/mod.ts) page!