Skip to content

A simple, lightweight, Maybe implementation in JavaScript.

Notifications You must be signed in to change notification settings

johnpaulada/maybe

Repository files navigation

Maybe

A simple Maybe implementation in JavaScript.

forthebadge forthebadge

Getting Started

Importing the library

To use the library, first import it:

In Node:

const Maybe = require('@johnpaulada/maybe')

As ES Module:

import Maybe from '@johnpaulada/maybe'

On the browser:

<script src="https://cdn.jsdelivr.net/npm/@johnpaulada/maybe@3.0.2/maybe.min.js"></script>

Using the library

To create a Maybe (Just/Nothing) use the of() method like this:

const value = Maybe.of(1) // Just(1)

To work with the value, you can map() for example:

const plusFive = value.map(x => x + 5) // Just(6)

To get the value outside of Maybe, use the reduce() method:

const sixValue = plusFive.reduce(x => x) // 6

or the value() method:

const sixValue = plusFive.value(0)

This will get the value of the Maybe if it's a Just and will return a 0 if it's a Nothing.

Development

  1. Install Yarn.
  2. Install Rollup.
  3. Run yarn on the terminal to install dependencies.
  4. Running rollup -c will build the library.

Roadmap

  • Lazy Evaluation
  • Example for ap
  • Example for branch

License

MIT

About

A simple, lightweight, Maybe implementation in JavaScript.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published