@vitorluizc/maybedeprecated

🌯 The prettiest TypeScript implementation of Maybe monad.

Usage no npm install needed!

<script type="module">
  import vitorluizcMaybe from 'https://cdn.skypack.dev/@vitorluizc/maybe';
</script>

README

@vitorluizc/maybe

Build Status License Library minified size Library minified + gzipped size

Maybe wraps unsafe values and provide methods to handle them in a safe flow.

Usage

import { createMaybe } from '@vitorluizc/maybe'

const repositories =
  createMaybe(field.value)
    .map(name => users.find(user => user.name.includes(name)))
    .map(user => repositories.filter(repository => repository.owner === user.id))

repositories.get([]).forEach(repository => {
  container.innerHTML += renderRepository(repository);
})

Installation

This library is published in the NPM registry and can be installed using any compatible package manager.

npm install @vitorluizc/maybe --save

# For Yarn, use the command below.
yarn add @vitorluizc/maybe

Installation from CDN

This module has an UMD bundle available through JSDelivr and Unpkg CDNs.

<script src="https://unpkg.com/@vitorluizc/maybe@^2.0.0"></script>

<script>
  // jQuery is here just to show the example.

  $("#field-name").on("change", event => {
    Maybe.createMaybe(event.target.value)
      .map(name => users.filterByName(name))
      .map(users => $("#template-users").render(users));
  });
</script>

Documentation

Documentation generated from source files by Typedoc.

License

Released under MIT License.