3.0.2 • Published 6 years ago

@johnpaulada/maybe v3.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
6 years ago

Maybe

A simple Maybe implementation in JavaScript.

forthebadge forthebadge

npm.io

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

3.0.2

6 years ago

3.0.1

6 years ago

3.0.0

6 years ago

2.1.2

6 years ago

2.1.1

6 years ago

2.1.0

6 years ago

2.0.3

6 years ago

2.0.2

6 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.0.0

7 years ago