https://github.com/tsukinoko-kun/opsult
A simple implementation of Option, Result and Future types in TypeScript
https://github.com/tsukinoko-kun/opsult
future option result result-type rust type-library typescript
Last synced: 14 days ago
JSON representation
A simple implementation of Option, Result and Future types in TypeScript
- Host: GitHub
- URL: https://github.com/tsukinoko-kun/opsult
- Owner: tsukinoko-kun
- License: mit
- Created: 2022-12-15T20:59:36.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-03-05T11:01:39.000Z (about 2 years ago)
- Last Synced: 2025-05-06T04:58:02.071Z (15 days ago)
- Topics: future, option, result, result-type, rust, type-library, typescript
- Language: TypeScript
- Homepage: https://frank-mayer.github.io/opsult/
- Size: 778 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
![]()
opsult## Basic overfiew
A implementation of Option, Result and Future types in TypeScript. If you know Rust, you will feel right at home.
### Option
```TypeScript
import { Option } from '@frank-mayer/opsult/Option';const a: Option = some(1);
const b: Option = none();
const c: Option = some(2);a.andThen((x: number) => c.map((y: number) => x + y)); // some(3)
b.andThen((x: number) => c.map((y: number) => x + y)); // none()
```### Result
```TypeScript
import { Result } from '@frank-mayer/opsult/Result';const a: Result = ok(1);
const b: Result = err('error');
const c: Result = ok(2);a.andThen((x: number) => c.map((y: number) => x + y)); // ok(3)
b.andThen((x: number) => c.map((y: number) => x + y)); // err('error')
```### Future
```TypeScript
import { Future } from '@frank-mayer/opsult/Future';const fut: Future = new Future((ok, err) => {
setTimeout(() => err("timeout"), 1000);complexAsyncOperation((x: number) => {
ok(x);
});
})const res: Result = await fut;
res.match({
ok: (x: number) => console.log(x),
err: (e: string) => console.error(e)
});
```[Read the docs to learn on how to use it.](https://Frank-Mayer.github.io/opsult)
## Installation
```bash
npm i @frank-mayer/opsult
```