monads.maybe
Advanced tools
Comparing version 0.1.1 to 0.2.0
151
lib/index.js
@@ -24,69 +24,89 @@ // Generated by LiveScript 1.2.0 | ||
* | ||
* @module monads.maybe | ||
* @author Quildreen Motta | ||
* @exports Maybe | ||
* + module: monads.maybe | ||
* + author: Quildreen Motta | ||
* + exports: Maybe | ||
*/ | ||
(function(){ | ||
var Applicative, Functor, Monad, Show, Eq, Recoverable, Maybe, Nothing; | ||
Applicative = { | ||
of: function(v){ | ||
return new Maybe(v); | ||
}, | ||
ap: function(b){ | ||
return b.map(this.value); | ||
} | ||
}; | ||
Functor = { | ||
map: function(f){ | ||
return this.of(f(this.value)); | ||
} | ||
}; | ||
Monad = { | ||
chain: function(f){ | ||
return f(this.value); | ||
} | ||
}; | ||
Show = { | ||
toString: function(){ | ||
return "Maybe.Just(" + this.value + ")"; | ||
} | ||
}; | ||
Eq = { | ||
isEqual: function(a){ | ||
return a.isJust && a.value === this.value; | ||
} | ||
}; | ||
Recoverable = { | ||
orElse: function(_){ | ||
return this; | ||
} | ||
}; | ||
var Maybe, Just, Nothing; | ||
Maybe = (function(){ | ||
Maybe.displayName = 'Maybe'; | ||
var prototype = Maybe.prototype, constructor = Maybe; | ||
importAll$(prototype, arguments[0]); | ||
importAll$(prototype, arguments[1]); | ||
importAll$(prototype, arguments[2]); | ||
importAll$(prototype, arguments[3]); | ||
importAll$(prototype, arguments[4]); | ||
importAll$(prototype, arguments[5]); | ||
function Maybe(a){ | ||
this.value = a; | ||
} | ||
Maybe.Nothing = function(){ | ||
function Maybe(){} | ||
prototype.Nothing = function(){ | ||
return Nothing; | ||
}; | ||
Maybe.Just = function(v){ | ||
return new Maybe(v); | ||
prototype.Just = function(a){ | ||
return new Just(a); | ||
}; | ||
prototype.fromNullable = function(a){ | ||
switch (false) { | ||
case a == null: | ||
return Nothing; | ||
default: | ||
return new Just(a); | ||
} | ||
}; | ||
prototype.isNothing = false; | ||
prototype.isJust = false; | ||
prototype.of = function(a){ | ||
return new Just(a); | ||
}; | ||
prototype.ap = function(_){ | ||
throw Error('unimplemented'); | ||
}; | ||
prototype.map = function(_){ | ||
throw Error('unimplemented'); | ||
}; | ||
prototype.chain = function(_){ | ||
throw Error('unimplemented'); | ||
}; | ||
prototype.toString = function(){ | ||
throw Error('unimplemented'); | ||
}; | ||
prototype.isEqual = function(_){ | ||
throw Error('unimplemented'); | ||
}; | ||
prototype.get = function(){ | ||
throw Error('unimplemented'); | ||
}; | ||
prototype.getOrElse = function(_){ | ||
throw Error('unimplemented'); | ||
}; | ||
prototype.orElse = function(_){ | ||
throw Error('unimplemented'); | ||
}; | ||
return Maybe; | ||
}()); | ||
Just = (function(superclass){ | ||
var prototype = extend$((import$(Just, superclass).displayName = 'Just', Just), superclass).prototype, constructor = Just; | ||
function Just(value){ | ||
this.value = value; | ||
} | ||
prototype.isJust = true; | ||
prototype.ap = function(b){ | ||
return b.map(this.value); | ||
}; | ||
prototype.map = function(f){ | ||
return this.of(f(this.value)); | ||
}; | ||
prototype.chain = function(f){ | ||
return f(this.value); | ||
}; | ||
prototype.toString = function(){ | ||
return "Maybe.Just(" + this.value + ")"; | ||
}; | ||
prototype.isEqual = function(a){ | ||
return a.isJust && a.value === this.value; | ||
}; | ||
prototype.get = function(){ | ||
return this.value; | ||
}; | ||
prototype.getOrElse = function(_){ | ||
prototype.getOrElse = function(a){ | ||
return this.value; | ||
}; | ||
return Maybe; | ||
}(Applicative, Functor, Monad, Show, Eq, Recoverable)); | ||
prototype.orElse = function(){ | ||
return this; | ||
}; | ||
return Just; | ||
}(Maybe)); | ||
Nothing = new (function(superclass){ | ||
@@ -96,17 +116,19 @@ var prototype = extend$(import$(constructor, superclass), superclass).prototype; | ||
prototype.isNothing = true; | ||
prototype.isJust = false; | ||
prototype.ap = function(b){ | ||
return b; | ||
}; | ||
prototype.map = function(){ | ||
prototype.map = function(f){ | ||
return this; | ||
}; | ||
prototype.chain = function(){ | ||
prototype.chain = function(f){ | ||
return this; | ||
}; | ||
prototype.orElse = function(f){ | ||
return f(); | ||
prototype.toString = function(){ | ||
return "Maybe.Nothing"; | ||
}; | ||
prototype.isEqual = function(a){ | ||
return a.isNothing; | ||
}; | ||
prototype.get = function(){ | ||
throw new Error("Can't get() the value of Nothing."); | ||
throw new TypeError("Can't extract the value of a Nothing"); | ||
}; | ||
@@ -116,15 +138,8 @@ prototype.getOrElse = function(a){ | ||
}; | ||
prototype.toString = function(){ | ||
return "Maybe.Nothing"; | ||
prototype.orElse = function(f){ | ||
return f(); | ||
}; | ||
prototype.isEqual = function(a){ | ||
return a.isNothing; | ||
}; | ||
return constructor; | ||
}(Maybe)); | ||
module.exports = Maybe; | ||
function importAll$(obj, src){ | ||
for (var key in src) obj[key] = src[key]; | ||
return obj; | ||
} | ||
module.exports = new Maybe; | ||
function extend$(sub, sup){ | ||
@@ -131,0 +146,0 @@ function fun(){} fun.prototype = (sub.superclass = sup).prototype; |
{ | ||
"name": "monads.maybe", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"description": "A monad for values that may not be available or computations that may fail.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -112,5 +112,12 @@ Monads: Maybe | ||
( TBD ) | ||
You can [read the documentation online][docs] or build it yourself: | ||
$ git clone git://github.com/folktale/monads.maybe.git | ||
$ cd monads.maybe | ||
$ npm install | ||
$ make documentation | ||
Then open the file `docs/literate/index.html` in your browser. | ||
## Platform support | ||
@@ -136,1 +143,2 @@ | ||
[es5-shim]: https://github.com/kriskowal/es5-shim | ||
[docs]: http://folktale.github.io/monads.maybe |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
143
0
25200
11
153
1