Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Version 0.0.1
  • Loading branch information
santoshrajan committed Mar 30, 2013
1 parent ebb7d94 commit 3abf0bd
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
22 changes: 22 additions & 0 deletions LICENSE
@@ -0,0 +1,22 @@
Copyright (c) 2013 Santosh Rajan

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
33 changes: 33 additions & 0 deletions monad.js
@@ -0,0 +1,33 @@
(function(exports){

exports.doMonad = function(monad) {
var args = arguments, scope = {};
function iterator(i) {
if (args.length === i + 1) {
return monad.mResult(args[i](scope));
}
var varName = args[i];
var func = args[i + 1];
var value = func(scope);
return monad.mBind(value, function(value) {
scope[varName] = value;
return iterator(i + 2);
});
}
return iterator(1);
}

exports.arrayMonad = {
mBind: function(mValue, mFunc) {
var accum = [];
mValue.forEach(function(elem){
accum = accum.concat(mFunc(elem));
});
return accum;
},
mResult: function(value) {
return [value];
}
}

})(typeof exports === 'undefined'? this['monadjs']={}: exports);
10 changes: 10 additions & 0 deletions package.json
@@ -0,0 +1,10 @@
{
"name" : "monadjs",
"description" : "Monad Library for JavaScript.",
"keywords" : ["monads", "functional", "javascript", "server", "client", "browser"],
"author" : "Santosh Rajan <santrajan@gmail.com>",
"repository" : {"type": "git", "url": "git://github.com/santoshrajan/monadjs.git"},
"main" : "monad.js",
"version" : "0.0.1",
"license" : "MIT"
}

0 comments on commit 3abf0bd

Please sign in to comment.