Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ramda-fantasy

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ramda-fantasy - npm Package Compare versions

Comparing version 0.1.0 to 0.2.0

src/lift2.js

3

index.js

@@ -6,4 +6,7 @@ module.exports = {

IO: require('./src/IO'),
lift2: require('./src/lift2'),
lift3: require('./src/lift3'),
Maybe: require('./src/Maybe'),
Tuple: require('./src/Tuple'),
Reader: require('./src/Reader')
};

8

package.json

@@ -5,3 +5,3 @@ {

"description": "Fantasy Land compatible types for easy integration with Ramda",
"version": "0.1.0",
"version": "0.2.0",
"homepage": "https://www.github.com/ramda/ramda-fantasy",

@@ -14,8 +14,12 @@ "license": "MIT",

"scripts": {
"jshint": "node_modules/.bin/jshint src/* test/*",
"pretest": "npm run jshint",
"test": "mocha"
},
"dependencies": {
"ramda": "^0.10.0"
"ramda": "^0.13.0"
},
"devDependencies": {
"jshint": "~2.7.0",
"jsverify": "^0.5.1",
"mocha": "^2.1.0",

@@ -22,0 +26,0 @@ "uglify-js": "2.4.x",

@@ -17,9 +17,13 @@ ramda-fantasy

* Either
* Future
* Identity
* IO
* Maybe
* Reader
Name | Setoid | Semigroup | Functor | Applicative | Monad | Comonad |
---------- | :-----: | :-------: | :-----: | :---------: | :---: | :------: |
Either | **✔︎** | | **✔︎** | **✔︎** | **✔︎** | |
Future | **✔︎** | | **✔︎** | **✔︎** | **✔︎** | |
Identity | **✔︎** | | **✔︎** | **✔︎** | **✔︎** | |
IO | **✔︎** | | **✔︎** | **✔︎** | **✔︎** | |
Maybe | **✔︎** | | **✔︎** | **✔︎** | **✔︎** | |
Reader | **✔︎** | | **✔︎** | **✔︎** | **✔︎** | |
Tuple | **✔︎** | **✔︎** | **✔︎** | **✔︎** | | |
Access like so:

@@ -26,0 +30,0 @@ ```

var util = require('./internal/util');
function Either(left, right) {
switch (arguments.length) {
case 0:
throw new TypeError('no arguments to Either.fromNullable');
throw new TypeError('no arguments to Either');
case 1:

@@ -18,4 +19,4 @@ return function(right) {

Either.of = Either.prototype.of = function(value) {
return Either.Right(value);
Either.of = Either.prototype.of = function(value) {
return Either.Right(value);
};

@@ -25,5 +26,3 @@

Either.equals = Either.prototype.equals = function(that) {
return this.constructor === that.constructor && this.value === that.value;
};
Either.equals = Either.prototype.equals = util.getEquals(Either);

@@ -37,14 +36,18 @@

_Right.prototype.map = function(fn) {
return new _Right(fn(this.value));
_Right.prototype.map = function(fn) {
return new _Right(fn(this.value));
};
_Right.prototype.ap = function(that) {
return that.map(this.value);
_Right.prototype.ap = function(that) {
return that.map(this.value);
};
_Right.prototype.chain = function(f) {
return f(this.value);
_Right.prototype.chain = function(f) {
return f(this.value);
};
_Right.prototype.bimap = function(_, f) {
return new _Right(f(this.value));
};
Either.Right = function(value) {

@@ -63,2 +66,6 @@ return new _Right(value);

_Left.prototype.bimap = function(f) {
return new _Left(f(this.value));
};
Either.Left = function(value) {

@@ -65,0 +72,0 @@ return new _Left(value);

@@ -1,2 +0,2 @@

module.exports = Future;
var R = require('ramda');

@@ -18,3 +18,26 @@ // `f` is a function that takes two function arguments: `reject` (failure) and `resolve` (success)

Future.prototype.ap = function(m) {
return this.chain(function(f) { return m.map(f); });
var self = this;
return new Future(function(rej, res) {
var applyFn, val;
var doReject = R.once(rej);
function resolveIfDone() {
if (applyFn != null && val != null) {
return res(applyFn(val));
}
}
self.fork(doReject, function(fn) {
applyFn = fn;
resolveIfDone();
});
m.fork(doReject, function(v) {
val = v;
resolveIfDone();
});
});
};

@@ -44,1 +67,20 @@

// see above.
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));
});
});
};
Future.reject = function(val) {
return new Future(function(reject) {
reject(val);
});
};
module.exports = Future;

@@ -1,3 +0,4 @@

module.exports = Identity;
var util = require('./internal/util');
/**

@@ -77,4 +78,4 @@ * A data type that holds a value and exposes a monadic api.

// equality method to enable testing
Identity.prototype.equals = function(that) {
return this.value === that.value;
};
Identity.prototype.equals = util.getEquals(Identity);
module.exports = Identity;

@@ -0,1 +1,2 @@

var eqDeep = require('ramda').eqDeep;

@@ -9,2 +10,8 @@

getEquals: function(constructor) {
return function equals(that) {
return that instanceof constructor && eqDeep(this.value, that.value);
};
},
extend: function(Child, Parent) {

@@ -11,0 +18,0 @@ function Ctor() {

@@ -53,3 +53,3 @@ var R = require('ramda');

this.fn === that.fn ||
IO.runIO(this) === IO.runIO(that);
R.eqDeep(IO.runIO(this), IO.runIO(that));
};

@@ -5,3 +5,3 @@ var util = require('./internal/util.js');

return x == null ? _nothing : Maybe.Just(x);
};
}

@@ -30,3 +30,10 @@ function _Just(x) {

Maybe.isJust = function(x) {
return x instanceof _Just;
};
Maybe.isNothing = function(x) {
return x === _nothing;
};
// functor

@@ -46,3 +53,3 @@ _Just.prototype.map = function(f) {

_Nothing.prototype.ap = util.identity;
_Nothing.prototype.ap = util.returnThis;

@@ -62,3 +69,3 @@ // applicative

//
//
_Just.prototype.datatype = _Just;

@@ -73,5 +80,3 @@

// equality method to enable testing
_Just.prototype.equals = function(that) {
return that instanceof _Just && this.value === that.value;
};
_Just.prototype.equals = util.getEquals(_Just);

@@ -82,3 +87,19 @@ _Nothing.prototype.equals = function(that) {

Maybe.prototype.isNothing = function() {
return this === _nothing;
};
Maybe.prototype.isJust = function() {
return this instanceof _Just;
};
_Just.prototype.getOrElse = function() {
return this.value;
};
_Nothing.prototype.getOrElse = function(a) {
return a;
};
module.exports = Maybe;

@@ -1,3 +0,4 @@

module.exports = Reader;
var R = require('ramda');
function Reader(run) {

@@ -16,4 +17,4 @@ if (!(this instanceof Reader)) {

var reader = this;
return new Reader(function() {
return f(reader.run()).run();
return new Reader(function(r) {
return f(reader.run(r)).run(r);
});

@@ -48,3 +49,5 @@ };

this.run === that.run ||
Reader.run(this) === Reader.run(that);
R.eqDeep(Reader.run(this), Reader.run(that));
};
module.exports = Reader;
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc