Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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?

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));
```