rusty-ts
Rust-inspired Option
and Result
types for TypeScript.
Usage
npm install --save rusty-ts
Option
; ;; ;; // Logs "FOOFOOFOO"fd;
Result
; ;; ;; // Logs "FOOFOOFOO"fd;
Option
and option
(or Result
and result
)?
Why Option
is just an interface—any Option
-compatible code you write will be compatible with any implementation of Option
.
This gives you the flexibility to implement Option
however you like.
However, you probably don't want to write your own implementation, so we provide you with one out-of-the-box.
The option
object provides a namespace that groups the factories
of the default implementation.
To instantiate an Some or None variant, simply call option.some()
or option.none()
, respectively.
The same goes for Result
(the interface), and result
(the namespace containing the factory functions).
API Docs
Docs can be found here.