diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..5e0b352 --- /dev/null +++ b/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. \ No newline at end of file diff --git a/monad.js b/monad.js new file mode 100644 index 0000000..e5b0f97 --- /dev/null +++ b/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); diff --git a/package.json b/package.json new file mode 100644 index 0000000..7acf85c --- /dev/null +++ b/package.json @@ -0,0 +1,10 @@ +{ + "name" : "monadjs", + "description" : "Monad Library for JavaScript.", + "keywords" : ["monads", "functional", "javascript", "server", "client", "browser"], + "author" : "Santosh Rajan ", + "repository" : {"type": "git", "url": "git://github.com/santoshrajan/monadjs.git"}, + "main" : "monad.js", + "version" : "0.0.1", + "license" : "MIT" +} \ No newline at end of file