3.0.2 • Published 8 years ago
@johnpaulada/maybe v3.0.2
Maybe
A simple Maybe implementation in JavaScript.
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) // 6or 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
- Install Yarn.
- Install Rollup.
- Run
yarnon the terminal to install dependencies. - Running
rollup -cwill build the library.
Roadmap
- Lazy Evaluation
- Example for
ap - Example for
branch
License
MIT