sensible-maybe

A really small maybe function

Usage no npm install needed!

<script type="module">
  import sensibleMaybe from 'https://cdn.skypack.dev/sensible-maybe';
</script>

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

Installing

$ yarn add sensible-maybe

Examples

Maybe.of(getUser())
  .map((user) => user.name)
  .getOrElse("Not signed in");

Maybe.of(getUser()).either(
  (user) => <a href="/account">{user.name}</a>,
  () => <a href="/login">Login</a>
);

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