npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

monad-js

v1.0.6

Published

Douglas Crockford's monad library as UMD/ES6 module

Downloads

12

Readme

monad-js

npm version npm module downloads Build Status License: MIT Dependency Status devDependencies Status Coverage Status

Douglas Crockford's monad library as UMD/ES6 module

Installation

Make sure Node.js is installed. Then run:

npm install monad-js --save

Following bundles are available:

  • monad-js.js - UMD ES5 version for use in browser, node, etc.
  • monad-js.min.js - minified version of monad-js.js
  • monad-js.esm.js - ES6 module version, which can be used by bundlers like rollup or webpack

The package could also be downloaded directly from: https://registry.npmjs.org/monad-js/-/monad-js-1.0.6.tgz

More information

A monad is, depending on the language and implementation, an object / class / interface / type with two required operations:

  • unit (or return, inject) operation which sticks/shoves some arbitrary data a into a monad M a. It could be viewed as a constructor or factory taking in a and returning M a. In short: unit = a => M a
  • bind (or pipe, >>=) operation taking in a monad M a and a function a => M b and combining them to return a new monad M b. In short: bind = (M a, a => M b) => M b

Reason for existence of monads is to be able to compose functions that otherwise could not be composed, as they may be working on different domains. See Brian Beckman: Don't fear the Monad (video) for an excellent explanation.

See also:

Douglas Crockford's code

Douglas Crockford on Monads (video)

Notes from Crockford on Monads

The Marvels of Monads by Wes Dyer

Eric Lippert on Monads in .NET

License

MIT

Motivation

I wanted to be able to easily add Douglas Crockford's monad work to my projects via npm.

You are welcomed to improve this implementation or provide feedback. Please feel free to Fork, create a Pull Request or submit Issues. Thank you!

Development

npm install
npm run build

API Reference

monadJs.identity

The Identity Monad

 const monad = identity("Hello world.");
 monad.bind(alert);

Kind: static property of monadJs

monadJs.maybe

Maybe monad is used to guard against Null Pointer Exceptions.

 const monad = maybe(null);
 monad.bind(alert);    // Nothing happens.

Kind: static property of monadJs

monadJs.makeMonad

The makeMonad function is a macroid that produces monad constructor functions. It can take an optional modifier function, which is a function that is allowed to modify new monads at the end of the construction processes.

A monad constructor (sometimes called unit or return in some mythologies) comes with three methods, lift, liftValue, and method, all of which can add methods and properties to the monad's prototype.

A monad has a bind method that takes a function that receives a value and is usually expected to return a monad.

   const identity = makeMonad();
   const monad = identity("Hello world.");
   monad.bind(alert);

   const ajax = makeMonad()
     .lift('alert', alert);
   const monad = ajax("Hello world.");
   monad.alert();

   const maybe = makeMonad(function (monad, value) {
       if (value === null || value === undefined) {
           monad.isNull = true;
           monad.bind = function () {
               return monad;
           };
           return null;
       }
       return value;
   });
   const monad = maybe(null);
   monad.bind(alert);    // Nothing happens.

Kind: static property of monadJs

monadJs.vow

Create a vow object, used to handle promises

NOTE: ES6 has native support for Promises. This implementation could still be used to create promises in ES5 though.

Kind: static constant of monadJs