https://github.com/pagequit/unwrap
Yet another Option<T> and Result<T, E>, implemented for TypeScript.
https://github.com/pagequit/unwrap
deno typescript
Last synced: 3 months ago
JSON representation
Yet another Option<T> and Result<T, E>, implemented for TypeScript.
- Host: GitHub
- URL: https://github.com/pagequit/unwrap
- Owner: pagequit
- License: mit
- Created: 2022-09-12T16:56:49.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2024-03-12T18:50:44.000Z (over 2 years ago)
- Last Synced: 2025-10-20T18:35:11.441Z (8 months ago)
- Topics: deno, typescript
- Language: TypeScript
- Homepage:
- Size: 95.7 KB
- Stars: 4
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# unwrap
Yet another TypeScript `Option` and `Result` implementation.
## Examples
```ts
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
import { Collection, None, Some } from "https://deno.land/x/unwrap/mod.ts";
type User = { name: string; age: number };
const users = Collection.from([
["#123", { name: "Alice", age: 32 }],
["#321", { name: "Bob", age: 23 }],
]);
const alice = users.get("#123");
assertEquals(alice, Some({ name: "Alice", age: 32 }));
const charlie = users.get("#000");
assertEquals(charlie, None());
const conditionalMappedValue = users.get("#123").and(users.get("#321")).match({
Some: (user) => user.name + " is " + user.age.toString(),
None: () => "never",
});
assertEquals(conditionalMappedValue, "Bob is 23");
```
```ts
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
import { Result, teaCall } from "https://deno.land/x/unwrap/mod.ts";
type User = { name: string; age: number };
const charlie: Result = teaCall(
JSON.parse,
'{ "name": "Charlie", "age": 33 }',
);
assertEquals(charlie.unwrap().name, "Charlie");
```