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 🙏

© 2026 – Pkg Stats / Ryan Hefner

coffee-monad

v0.1.5

Published

Monad implementations in Coffeescript

Readme

Learn You Monad in Coffeescript

Monad implementations in Coffeescript for learning and practice. The goal is to make it as a guide for Coffeescript programmers to learn Monads.

What is Monad?

  • In general, Monad is a design pattern
  • Specifically, Monad is a data structure which implements Monad type class and satisfies Monad laws

Monad was introduced in Haskell, but any language which supports higher order functions can implement Monads, such as Javascript/Coffeescript

Monad type class

Type class is a concept in Haskell. You can treat it as an interface in Java. Monad type class defines two functions, unit and return.

  • unit is to wrap a value into a monad. In Haskell it's named return.
  • bind is to unwrap the value and apply it to a function which takes the value as input and outputs a monad. In Haskell, it's >>= and in Scala it's flatMap.

We use Monad's name as unit function for conveniences, so you can write Maybe(5) instead of Maybe.unit(5).

In Haskell, bind function is infix operator >>=, so when you bind, it looks like

m >>= \ a -> m

Javascript doesn't support operator overloading, so it would look like

bind m (a)-> m

It's not as convenient as Haskell, so we leverage Javascript's OO nature and make bind as a method of monad. Thus it looks like

m.bind (a)-> m

Monad laws

  • Left identity: unit(a).bind f == f a
  • Right identity: m.bind unit == m
  • Associativity: (m.bind f).bind g == m.bind (x)-> f(x).bind g

How to use monad

Haskell

do
  a <- m(a)
  b <- m(b)
  c <- m(c)
  return (a+b+c)

    ||
    \/

m(a) >>= \a -> m(b) >>= \b -> m(c) >>= \c m(a+b+c)

Coffeescript

m(a).bind (a)->
  m(b).bind (b)->
    m(c).bind (c)->
      m(a+b+c)

Haskell has do-notation, but it's actually syntax sugar for bind(>>=). Coffeescript doesn't support do-notation, but it looks like similar to Haskell binding combinations.

Installation

$ npm install coffee-monad

Unit Test

$ jasmine-node --coffee --verbose spec/

Change Log

  • update README (Dec. 1, 2014)
  • State monad (Nov. 30, 2014)
  • Writer, Reader monad (Nov. 29, 2014)
  • IO monad (Nov. 29, 2014)
  • Maybe, List monad (Nov. 28, 2014)