Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/toyobayashi/rust-enum
https://github.com/toyobayashi/rust-enum
Last synced: 10 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/toyobayashi/rust-enum
- Owner: toyobayashi
- Created: 2022-03-29T10:17:01.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2022-03-29T10:20:21.000Z (almost 3 years ago)
- Last Synced: 2024-11-05T22:46:10.099Z (about 2 months ago)
- Language: TypeScript
- Size: 16.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Rust Enum for TypeScript
[API](https://github.com/toyobayashi/rust-enum/blob/main/docs/api/index.md)
```ts
const x = Option.Some(2)
const y = Option.None()x.unwrap() === 2
y.unwrapOr(2) === 2
y.unwrapOrElse(() => 2) === 2try {
y.unwrap()
} catch (_) {}x.isSome() === y.isNone()
x.and(Option.None()).isNone() === true
x.and(Option.Some(3)).unwrap() === 3const result = matchEnum(x)({
Some: (value) => value,
None: () => 0
})result === 2
const result2 = matchEnum(y)({
Some: (value) => value,
None: () => 0
})result2 === 0
```