0.0.2 • Published 13 years ago
yami-js v0.0.2
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-jsFeatures
- Haskell do-notation mimic implementation.
- Maybe, Writer and Random monads.
- 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 + yFor more examples, please take a look at:
example.jsFor more advaned monadic usage, please take a look at the quicksort implementation:
lib/utils.js