ramda-fantasy
Advanced tools
Comparing version 0.2.0 to 0.3.0
{ | ||
"author": "Michael Hurley <mh@buzzdecafe.com> (buzzdecafe.com)", | ||
"contributors": [ | ||
{ | ||
"name": "Michael Hurley", | ||
"email": "mh@buzzdecafe.com", | ||
"web": "http://buzzdecafe.com" | ||
}, | ||
{ | ||
"name": "Ludwig Magnusson", | ||
"email": "ludwig@mediatool.com" | ||
} | ||
], | ||
"name": "ramda-fantasy", | ||
"description": "Fantasy Land compatible types for easy integration with Ramda", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"homepage": "https://www.github.com/ramda/ramda-fantasy", | ||
@@ -13,10 +24,15 @@ "license": "MIT", | ||
"scripts": { | ||
"jscs": "node_modules/.bin/jscs src/* test/*", | ||
"jshint": "node_modules/.bin/jshint src/* test/*", | ||
"pretest": "npm run jshint", | ||
"release-major": "xyz --repo git@github.com:ramda/ramda-fantasy.git --increment major", | ||
"release-minor": "xyz --repo git@github.com:ramda/ramda-fantasy.git --increment minor", | ||
"release-patch": "xyz --repo git@github.com:ramda/ramda-fantasy.git --increment patch", | ||
"test": "mocha" | ||
}, | ||
"dependencies": { | ||
"ramda": "^0.13.0" | ||
"ramda": "^0.15.0" | ||
}, | ||
"devDependencies": { | ||
"jscs": "1.13.x", | ||
"jshint": "~2.7.0", | ||
@@ -23,0 +39,0 @@ "jsverify": "^0.5.1", |
@@ -0,1 +1,3 @@ | ||
var R = require('ramda'); | ||
var util = require('./internal/util'); | ||
@@ -5,12 +7,12 @@ | ||
function Either(left, right) { | ||
switch (arguments.length) { | ||
case 0: | ||
throw new TypeError('no arguments to Either'); | ||
case 1: | ||
return function(right) { | ||
return right == null ? Either.Left(left) : Either.Right(right); | ||
}; | ||
default: | ||
return right == null ? Either.Left(left) : Either.Right(right); | ||
} | ||
switch (arguments.length) { | ||
case 0: | ||
throw new TypeError('no arguments to Either'); | ||
case 1: | ||
return function(right) { | ||
return right == null ? Either.Left(left) : Either.Right(right); | ||
}; | ||
default: | ||
return right == null ? Either.Left(left) : Either.Right(right); | ||
} | ||
} | ||
@@ -31,3 +33,3 @@ | ||
function _Right(x) { | ||
this.value = x; | ||
this.value = x; | ||
} | ||
@@ -37,19 +39,27 @@ util.extend(_Right, Either); | ||
_Right.prototype.map = function(fn) { | ||
return new _Right(fn(this.value)); | ||
return new _Right(fn(this.value)); | ||
}; | ||
_Right.prototype.ap = function(that) { | ||
return that.map(this.value); | ||
return that.map(this.value); | ||
}; | ||
_Right.prototype.chain = function(f) { | ||
return f(this.value); | ||
return f(this.value); | ||
}; | ||
_Right.prototype.bimap = function(_, f) { | ||
return new _Right(f(this.value)); | ||
return new _Right(f(this.value)); | ||
}; | ||
_Right.prototype.extend = function(f) { | ||
return new _Right(f(this)); | ||
}; | ||
_Right.prototype.toString = function() { | ||
return 'Either.Right(' + R.toString(this.value) + ')'; | ||
}; | ||
Either.Right = function(value) { | ||
return new _Right(value); | ||
return new _Right(value); | ||
}; | ||
@@ -60,3 +70,3 @@ | ||
function _Left(x) { | ||
this.value = x; | ||
this.value = x; | ||
} | ||
@@ -68,7 +78,13 @@ util.extend(_Left, Either); | ||
_Left.prototype.bimap = function(f) { | ||
return new _Left(f(this.value)); | ||
return new _Left(f(this.value)); | ||
}; | ||
_Left.prototype.extend = util.returnThis; | ||
_Left.prototype.toString = function() { | ||
return 'Either.Left(' + R.toString(this.value) + ')'; | ||
}; | ||
Either.Left = function(value) { | ||
return new _Left(value); | ||
return new _Left(value); | ||
}; | ||
@@ -75,0 +91,0 @@ |
@@ -5,6 +5,6 @@ var R = require('ramda'); | ||
function Future(f) { | ||
if (!(this instanceof Future)) { | ||
return new Future(f); | ||
} | ||
this.fork = f; | ||
if (!(this instanceof Future)) { | ||
return new Future(f); | ||
} | ||
this.fork = f; | ||
} | ||
@@ -14,3 +14,3 @@ | ||
Future.prototype.map = function(f) { | ||
return this.chain(function(a) { return Future.of(f(a)); }); | ||
return this.chain(function(a) { return Future.of(f(a)); }); | ||
}; | ||
@@ -48,4 +48,4 @@ | ||
Future.of = function(x) { | ||
// should include a default rejection? | ||
return new Future(function(_, resolve) { return resolve(x); }); | ||
// should include a default rejection? | ||
return new Future(function(_, resolve) { return resolve(x); }); | ||
}; | ||
@@ -60,6 +60,6 @@ | ||
Future.prototype.chain = function(f) { // Sorella's: | ||
return new Future(function(reject, resolve) { | ||
return this.fork(function(a) { return reject(a); }, | ||
function(b) { return f(b).fork(reject, resolve); }); | ||
}.bind(this)); | ||
return new Future(function(reject, resolve) { | ||
return this.fork(function(a) { return reject(a); }, | ||
function(b) { return f(b).fork(reject, resolve); }); | ||
}.bind(this)); | ||
}; | ||
@@ -72,18 +72,22 @@ | ||
Future.prototype.bimap = function(errFn, successFn) { | ||
var self = this; | ||
return new Future(function(reject, resolve) { | ||
self.fork(function(err) { | ||
reject(errFn(err)); | ||
}, function(val) { | ||
resolve(successFn(val)); | ||
}); | ||
var self = this; | ||
return new Future(function(reject, resolve) { | ||
self.fork(function(err) { | ||
reject(errFn(err)); | ||
}, function(val) { | ||
resolve(successFn(val)); | ||
}); | ||
}); | ||
}; | ||
Future.reject = function(val) { | ||
return new Future(function(reject) { | ||
reject(val); | ||
}); | ||
return new Future(function(reject) { | ||
reject(val); | ||
}); | ||
}; | ||
Future.prototype.toString = function() { | ||
return 'Future(' + R.toString(this.fork) + ')'; | ||
}; | ||
module.exports = Future; |
@@ -0,1 +1,3 @@ | ||
var R = require('ramda'); | ||
var util = require('./internal/util'); | ||
@@ -15,6 +17,6 @@ | ||
function Identity(x) { | ||
if (!(this instanceof Identity)) { | ||
return new Identity(x); | ||
} | ||
this.value = x; | ||
if (!(this instanceof Identity)) { | ||
return new Identity(x); | ||
} | ||
this.value = x; | ||
} | ||
@@ -29,3 +31,3 @@ | ||
Identity.of = function(x) { | ||
return new Identity(x); | ||
return new Identity(x); | ||
}; | ||
@@ -42,3 +44,3 @@ Identity.prototype.of = Identity.of; | ||
Identity.prototype.map = function(f) { | ||
return new Identity(f(this.value)); | ||
return new Identity(f(this.value)); | ||
}; | ||
@@ -54,3 +56,3 @@ | ||
Identity.prototype.ap = function(app) { | ||
return app.map(this.value); | ||
return app.map(this.value); | ||
}; | ||
@@ -68,3 +70,3 @@ | ||
Identity.prototype.chain = function(fn) { | ||
return fn(this.value); | ||
return fn(this.value); | ||
}; | ||
@@ -79,3 +81,3 @@ | ||
Identity.prototype.get = function() { | ||
return this.value; | ||
return this.value; | ||
}; | ||
@@ -86,2 +88,6 @@ | ||
Identity.prototype.toString = function() { | ||
return 'Identity(' + R.toString(this.value) + ')'; | ||
}; | ||
module.exports = Identity; |
@@ -1,2 +0,2 @@ | ||
var eqDeep = require('ramda').eqDeep; | ||
var _equals = require('ramda').equals; | ||
@@ -6,37 +6,37 @@ | ||
baseMap: function(f) { | ||
return f(this.value); | ||
}, | ||
baseMap: function(f) { | ||
return f(this.value); | ||
}, | ||
getEquals: function(constructor) { | ||
return function equals(that) { | ||
return that instanceof constructor && eqDeep(this.value, that.value); | ||
}; | ||
}, | ||
getEquals: function(constructor) { | ||
return function equals(that) { | ||
return that instanceof constructor && _equals(this.value, that.value); | ||
}; | ||
}, | ||
extend: function(Child, Parent) { | ||
function Ctor() { | ||
this.constructor = Child; | ||
} | ||
Ctor.prototype = Parent.prototype; | ||
Child.prototype = new Ctor(); | ||
Child.super_ = Parent.prototype; | ||
}, | ||
extend: function(Child, Parent) { | ||
function Ctor() { | ||
this.constructor = Child; | ||
} | ||
Ctor.prototype = Parent.prototype; | ||
Child.prototype = new Ctor(); | ||
Child.super_ = Parent.prototype; | ||
}, | ||
identity: function(x) { return x; }, | ||
identity: function(x) { return x; }, | ||
notImplemented: function(str) { | ||
return function() { | ||
throw new Error(str + ' is not implemented'); | ||
}; | ||
}, | ||
notCallable: function(fn) { | ||
return function() { | ||
throw new Error(fn + ' cannot be called directly'); | ||
}; | ||
}, | ||
notImplemented: function(str) { | ||
return function() { | ||
throw new Error(str + ' is not implemented'); | ||
}; | ||
}, | ||
returnThis: function() { return this; } | ||
notCallable: function(fn) { | ||
return function() { | ||
throw new Error(fn + ' cannot be called directly'); | ||
}; | ||
}, | ||
returnThis: function() { return this; } | ||
}; |
@@ -8,6 +8,6 @@ var R = require('ramda'); | ||
function IO(fn) { | ||
if (!(this instanceof IO)) { | ||
return new IO(fn); | ||
} | ||
this.fn = fn; | ||
if (!(this instanceof IO)) { | ||
return new IO(fn); | ||
} | ||
this.fn = fn; | ||
} | ||
@@ -17,11 +17,11 @@ | ||
IO.prototype.chain = function(f) { | ||
var io = this; | ||
return new IO(function() { | ||
return f(io.fn()).fn(); | ||
}); | ||
var io = this; | ||
return new IO(function() { | ||
return f(io.fn()).fn(); | ||
}); | ||
}; | ||
IO.prototype.map = function(f) { | ||
var io = this; | ||
return new IO(compose(f, io.fn)); | ||
var io = this; | ||
return new IO(compose(f, io.fn)); | ||
}; | ||
@@ -32,17 +32,17 @@ | ||
IO.prototype.ap = function(thatIo) { | ||
return this.chain(function(f) { | ||
return thatIo.map(f); | ||
}); | ||
return this.chain(function(f) { | ||
return thatIo.map(f); | ||
}); | ||
}; | ||
IO.runIO = function(io) { | ||
return io.runIO.apply(io, [].slice.call(arguments, 1)); | ||
return io.runIO.apply(io, [].slice.call(arguments, 1)); | ||
}; | ||
IO.prototype.runIO = function() { | ||
return this.fn.apply(this, arguments); | ||
return this.fn.apply(this, arguments); | ||
}; | ||
IO.prototype.of = function(x) { | ||
return new IO(function() { return x; }); | ||
return new IO(function() { return x; }); | ||
}; | ||
@@ -54,5 +54,9 @@ | ||
IO.prototype.equals = function(that) { | ||
return this === that || | ||
this.fn === that.fn || | ||
R.eqDeep(IO.runIO(this), IO.runIO(that)); | ||
return this === that || | ||
this.fn === that.fn || | ||
R.equals(IO.runIO(this), IO.runIO(that)); | ||
}; | ||
IO.prototype.toString = function() { | ||
return 'IO(' + R.toString(this.fn) + ')'; | ||
}; |
@@ -0,9 +1,11 @@ | ||
var R = require('ramda'); | ||
var util = require('./internal/util.js'); | ||
function Maybe(x) { | ||
return x == null ? _nothing : Maybe.Just(x); | ||
return x == null ? _nothing : Maybe.Just(x); | ||
} | ||
function _Just(x) { | ||
this.value = x; | ||
this.value = x; | ||
} | ||
@@ -18,7 +20,7 @@ util.extend(_Just, Maybe); | ||
Maybe.Nothing = function() { | ||
return _nothing; | ||
return _nothing; | ||
}; | ||
Maybe.Just = function(x) { | ||
return new _Just(x); | ||
return new _Just(x); | ||
}; | ||
@@ -31,7 +33,7 @@ | ||
Maybe.isJust = function(x) { | ||
return x instanceof _Just; | ||
return x instanceof _Just; | ||
}; | ||
Maybe.isNothing = function(x) { | ||
return x === _nothing; | ||
return x === _nothing; | ||
}; | ||
@@ -41,3 +43,3 @@ | ||
_Just.prototype.map = function(f) { | ||
return this.of(f(this.value)); | ||
return this.of(f(this.value)); | ||
}; | ||
@@ -51,3 +53,3 @@ | ||
_Just.prototype.ap = function(m) { | ||
return m.map(this.value); | ||
return m.map(this.value); | ||
}; | ||
@@ -83,3 +85,3 @@ | ||
_Nothing.prototype.equals = function(that) { | ||
return that === _nothing; | ||
return that === _nothing; | ||
}; | ||
@@ -103,3 +105,10 @@ | ||
_Just.prototype.toString = function() { | ||
return 'Maybe.Just(' + R.toString(this.value) + ')'; | ||
}; | ||
_Nothing.prototype.toString = function() { | ||
return 'Maybe.Nothing()'; | ||
}; | ||
module.exports = Maybe; | ||
@@ -5,35 +5,35 @@ var R = require('ramda'); | ||
function Reader(run) { | ||
if (!(this instanceof Reader)) { | ||
return new Reader(run); | ||
} | ||
this.run = run; | ||
if (!(this instanceof Reader)) { | ||
return new Reader(run); | ||
} | ||
this.run = run; | ||
} | ||
Reader.run = function(reader) { | ||
return reader.run.apply(reader, [].slice.call(arguments, 1)); | ||
return reader.run.apply(reader, [].slice.call(arguments, 1)); | ||
}; | ||
Reader.prototype.chain = function(f) { | ||
var reader = this; | ||
return new Reader(function(r) { | ||
return f(reader.run(r)).run(r); | ||
}); | ||
var reader = this; | ||
return new Reader(function(r) { | ||
return f(reader.run(r)).run(r); | ||
}); | ||
}; | ||
Reader.prototype.ap = function(a) { | ||
return this.chain(function(f) { | ||
return a.map(f); | ||
}); | ||
return this.chain(function(f) { | ||
return a.map(f); | ||
}); | ||
}; | ||
Reader.prototype.map = function(f) { | ||
return this.chain(function(a) { | ||
return Reader.of(f(a)); | ||
}); | ||
return this.chain(function(a) { | ||
return Reader.of(f(a)); | ||
}); | ||
}; | ||
Reader.prototype.of = function(a) { | ||
return new Reader(function() { | ||
return a; | ||
}); | ||
return new Reader(function() { | ||
return a; | ||
}); | ||
}; | ||
@@ -43,11 +43,15 @@ Reader.of = Reader.prototype.of; | ||
Reader.ask = Reader(function(a) { | ||
return a; | ||
return a; | ||
}); | ||
Reader.prototype.equals = function(that) { | ||
return this === that || | ||
this.run === that.run || | ||
R.eqDeep(Reader.run(this), Reader.run(that)); | ||
return this === that || | ||
this.run === that.run || | ||
R.equals(Reader.run(this), Reader.run(that)); | ||
}; | ||
Reader.prototype.toString = function() { | ||
return 'Reader(' + R.toString(this.run) + ')'; | ||
}; | ||
module.exports = Reader; |
@@ -1,46 +0,45 @@ | ||
var eqDeep = require('ramda').eqDeep; | ||
var R = require('ramda'); | ||
function Tuple(x, y) { | ||
switch (arguments.length) { | ||
case 0: | ||
throw new TypeError('no arguments to Tuple'); | ||
case 1: | ||
return function(y) { | ||
return new _Tuple(x, y); | ||
}; | ||
default: | ||
return new _Tuple(x,y); | ||
} | ||
switch (arguments.length) { | ||
case 0: | ||
throw new TypeError('no arguments to Tuple'); | ||
case 1: | ||
return function(y) { | ||
return new _Tuple(x, y); | ||
}; | ||
default: | ||
return new _Tuple(x, y); | ||
} | ||
} | ||
function _Tuple(x, y) { | ||
this[0] = x; | ||
this[1] = y; | ||
this.length = 2; | ||
this[0] = x; | ||
this[1] = y; | ||
this.length = 2; | ||
} | ||
function ensureConcat(xs) { | ||
xs.forEach(function(x) { | ||
if(typeof x.concat != "function") { | ||
var display = x.show ? x.show() : x; | ||
throw new TypeError(display + " must be a semigroup to perform this operation"); | ||
} | ||
}); | ||
xs.forEach(function(x) { | ||
if (typeof x.concat != 'function') { | ||
throw new TypeError(R.toString(x) + ' must be a semigroup to perform this operation'); | ||
} | ||
}); | ||
} | ||
Tuple.of = function(x) { | ||
return Tuple(x, x); | ||
return Tuple(x, x); | ||
}; | ||
Tuple.fst = function(x) { | ||
return x[0]; | ||
return x[0]; | ||
}; | ||
Tuple.snd = function(x) { | ||
return x[1]; | ||
return x[1]; | ||
}; | ||
_Tuple.prototype.of = function(x) { | ||
return Tuple(this[0], x); | ||
return Tuple(this[0], x); | ||
}; | ||
@@ -50,4 +49,4 @@ | ||
_Tuple.prototype.concat = function(x) { | ||
ensureConcat([this[0], this[1]]); | ||
return Tuple(this[0].concat(x[0]), this[1].concat(x[1])); | ||
ensureConcat([this[0], this[1]]); | ||
return Tuple(this[0].concat(x[0]), this[1].concat(x[1])); | ||
}; | ||
@@ -57,3 +56,3 @@ | ||
_Tuple.prototype.map = function(f) { | ||
return Tuple(this[0], f(this[1])); | ||
return Tuple(this[0], f(this[1])); | ||
}; | ||
@@ -63,4 +62,4 @@ | ||
_Tuple.prototype.ap = function(m) { | ||
ensureConcat([this[0]]); | ||
return Tuple(this[0].concat(m[0]), this[1](m[1])); | ||
ensureConcat([this[0]]); | ||
return Tuple(this[0].concat(m[0]), this[1](m[1])); | ||
}; | ||
@@ -70,11 +69,9 @@ | ||
_Tuple.prototype.equals = function(that) { | ||
return that instanceof _Tuple && eqDeep(this[0], that[0]) && eqDeep(this[1], that[1]); | ||
return that instanceof _Tuple && R.equals(this[0], that[0]) && R.equals(this[1], that[1]); | ||
}; | ||
// show - not recursive yet. | ||
_Tuple.prototype.show = function() { | ||
return "Tuple(" + this[0] + ", " + this[1] + ")"; | ||
_Tuple.prototype.toString = function() { | ||
return 'Tuple(' + R.toString(this[0]) + ', ' + R.toString(this[1]) + ')'; | ||
}; | ||
module.exports = Tuple; | ||
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
46560
27
1378
6
2
+ Addedramda@0.15.1(transitive)
- Removedramda@0.13.0(transitive)
Updatedramda@^0.15.0