0.0.2 • Published 13 years ago

yami-js v0.0.2

Weekly downloads
10
License
-
Repository
github
Last release
13 years ago

yami-js

Yet another monad implementation for JavaScript.

Description

Yami-js is an attempt to implement the core functional programming concept of Monads in JavaScript. The model is Haskell and the powerful do-notation. Used syntax is meant to reflect the original Haskell notation.

Install

npm install yami-js

Features

  1. Haskell do-notation mimic implementation.
  2. Maybe, Writer and Random monads.
  3. Randomized monadic quick sort.

Example

An example add function using the Maybe monad would be:

/* monadic add */
function add(mx, my){
	var x = new Monad.Variable();
	var y = new Monad.Variable();
		
	return Monad.do([
		[x, function(){ return mx; }],
		[y, function(){ return my; }],
		function() { return Maybe.unit(x.get() + y.get()); }
	]).destruct();
}

The same function in Haskell:

add mx my =
	do
		x <- mx
		y <- my
		return x + y

For more examples, please take a look at:

example.js

For more advaned monadic usage, please take a look at the quicksort implementation:

lib/utils.js