Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rzane/sensible-maybe
Maybe you should use a Maybe?
https://github.com/rzane/sensible-maybe
functional-programming javascript maybe typescript
Last synced: about 2 months ago
JSON representation
Maybe you should use a Maybe?
- Host: GitHub
- URL: https://github.com/rzane/sensible-maybe
- Owner: rzane
- Created: 2019-03-08T20:10:06.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2022-07-20T06:07:40.000Z (over 2 years ago)
- Last Synced: 2024-11-02T01:06:33.177Z (3 months ago)
- Topics: functional-programming, javascript, maybe, typescript
- Language: TypeScript
- Homepage:
- Size: 626 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# sensible-maybe
A pretty barebones Maybe implementation in TypeScript. Let's try to stay practical. You don't need to build your entire application with this thing.
[View the documentation](docs/modules.md)
## Installing
$ yarn add sensible-maybe
## Examples
```tsx
Maybe.of(getUser())
.map((user) => user.name)
.getOrElse("Not signed in");Maybe.of(getUser()).either(
(user) => {user.name},
() => Login
);Maybe.of(getUser())
.filter((user) => user.isAdmin)
.map((user) => `Admin: ${user.name}`)
.getOrElse("Unauthorized!");Maybe.of(getUser())
.map((user) => user.name)
.forEach((name) => console.log(name));
```