Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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: 25 days ago
JSON representation
Rust-like error handling and options for TypeScript and Deno!
- Host: GitHub
- URL: https://github.com/OliverBrotchie/optionals
- Owner: OliverBrotchie
- License: mit
- Created: 2021-09-23T20:55:28.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-07-11T12:12:21.000Z (over 1 year ago)
- Last Synced: 2024-05-01T19:31:03.438Z (8 months ago)
- Topics: deno, error-handling, rust, typescript
- Language: TypeScript
- Homepage:
- Size: 128 KB
- Stars: 172
- Watchers: 4
- Forks: 7
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-deno - optionals - Rust-like error handling and options with exhaustive pattern matching. (Modules / Utils)
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!