ramda-fantasy
Advanced tools
Comparing version 0.7.0 to 0.8.0
{ | ||
"name": "ramda-fantasy", | ||
"description": "Fantasy Land compatible types for easy integration with Ramda", | ||
"version": "0.7.0", | ||
"version": "0.8.0", | ||
"authors": [ | ||
@@ -6,0 +6,0 @@ { |
@@ -143,1 +143,8 @@ # Either | ||
Returns a string representation of the `Either` instance. | ||
#### `either.either` | ||
```hs | ||
:: Either a b ~> (a -> c) -> (b -> c) -> c | ||
``` | ||
Used to extract the value out of the `Either` by providing a function to handle | ||
the types of values contained in both `Left` and `Right`. |
@@ -106,2 +106,9 @@ # Maybe | ||
#### `Maybe.toMaybe` | ||
```hs | ||
:: a? -> Maybe a | ||
``` | ||
Returns `Nothing` for a `null`/`undefined` value, otherwise a `Just` of the | ||
value for any other value. | ||
### Instance methods | ||
@@ -108,0 +115,0 @@ |
@@ -127,3 +127,3 @@ # Reader | ||
```hs | ||
:: Monad m => Reader r m a | ||
:: Monad m => ReaderT r m a | ||
``` | ||
@@ -142,3 +142,3 @@ A static `ReaderT` instance that just returns its environment. | ||
```hs | ||
:: Monad m => a -> Reader r m a | ||
:: Monad m => a -> ReaderT r m a | ||
``` | ||
@@ -149,3 +149,3 @@ Produces a pure `ReaderT` instance for the given value. | ||
```hs | ||
:: Monad m => m a -> Reader r m a | ||
:: Monad m => m a -> ReaderT r m a | ||
``` | ||
@@ -152,0 +152,0 @@ Lifts a monad value into a `ReaderT` instance. |
@@ -16,3 +16,3 @@ { | ||
"description": "Fantasy Land compatible types for easy integration with Ramda", | ||
"version": "0.7.0", | ||
"version": "0.8.0", | ||
"homepage": "https://www.github.com/ramda/ramda-fantasy", | ||
@@ -25,2 +25,4 @@ "license": "MIT", | ||
"scripts": { | ||
"build": "browserify -r ./index.js -s RF | derequire > dist/ramda-fantasy.js ", | ||
"postbuild": "uglifyjs dist/ramda-fantasy.js -m -c unused=false -o dist/ramda-fantasy.min.js", | ||
"jscs": "node_modules/.bin/jscs src/* test/*", | ||
@@ -38,2 +40,4 @@ "jshint": "node_modules/.bin/jshint src/* test/*", | ||
"devDependencies": { | ||
"browserify": "13.1.x", | ||
"derequire": "^2.0.3", | ||
"jscs": "1.13.x", | ||
@@ -40,0 +44,0 @@ "jshint": "~2.7.0", |
@@ -19,5 +19,6 @@ ramda-fantasy | ||
| [IO][12] | | | **✔︎** | **✔︎** | **✔︎** | | **✔︎** | | ||
| [Maybe][13] | **✔︎** | | **✔︎** | **✔︎** | **✔︎** | **✔︎** | **✔︎** | | ||
| [Maybe][13] | **✔︎** | **✔︎** | **✔︎** | **✔︎** | **✔︎** | **✔︎** | **✔︎** | | ||
| [Reader][14] | | | **✔︎** | **✔︎** | **✔︎** | | | | ||
| [Tuple][15] | **✔︎** | **✔︎** | **✔︎** | | | | | | ||
| [State][17] | | | **✔︎** | **✔︎** | **✔︎** | | **✔︎** | | ||
@@ -29,2 +30,4 @@ | ||
``` | ||
## available translations | ||
[Spanish](https://github.com/idcmardelplata/ramda-fantasy) | ||
@@ -47,1 +50,2 @@ [1]: https://github.com/fantasyland/fantasy-land | ||
[16]: https://github.com/fantasyland/fantasy-land#chainrec | ||
[17]: docs/State.md |
@@ -30,5 +30,2 @@ var curry = require('ramda/src/curry'); | ||
Either.equals = Either.prototype.equals = util.getEquals(Either); | ||
Either.either = curry(function either(leftFn, rightFn, e) { | ||
@@ -99,2 +96,4 @@ if (e instanceof _Left) { | ||
_Right.prototype.equals = util.getEquals(_Right); | ||
Either.Right = function(value) { | ||
@@ -126,2 +125,4 @@ return new _Right(value); | ||
_Left.prototype.equals = util.getEquals(_Left); | ||
Either.Left = function(value) { | ||
@@ -132,2 +133,7 @@ return new _Left(value); | ||
// either | ||
Either.prototype.either = function instanceEither(leftFn, rightFn) { | ||
return this.isLeft ? leftFn(this.value) : rightFn(this.value); | ||
}; | ||
module.exports = Either; |
@@ -54,2 +54,13 @@ var toString = require('ramda/src/toString'); | ||
Maybe.toMaybe = Maybe; | ||
// semigroup | ||
Just.prototype.concat = function(that) { | ||
return that.isNothing ? this : this.of( | ||
this.value.concat(that.value) | ||
); | ||
}; | ||
Nothing.prototype.concat = util.identity; | ||
// functor | ||
@@ -56,0 +67,0 @@ Just.prototype.map = function(f) { |
@@ -178,2 +178,42 @@ var R = require('ramda'); | ||
describe('#equals', function() { | ||
it('returns true if both contain equal values and are both Left', function() { | ||
assert.equal(true, Either.Left(1).equals(Either.Left(1))); | ||
}); | ||
it('returns true if both contain equal values and are both Right', function() { | ||
assert.equal(true, Either.Right(1).equals(Either.Right(1))); | ||
}); | ||
it('returns false if both contain equal values but are of different constructors', function() { | ||
assert.equal(false, Either.Left(1).equals(Either.Right(1))); | ||
}); | ||
it('returns false if both contain different values and are both Left', function() { | ||
assert.equal(false, Either.Left(0).equals(Either.Left(1))); | ||
}); | ||
it('returns false if both contain different values and are both Right', function() { | ||
assert.equal(false, Either.Right(0).equals(Either.Right(1))); | ||
}); | ||
}); | ||
describe('#either', function() { | ||
it('returns the value of a Left after applying the first function arg', function() { | ||
jsv.assert(jsv.forall(leftArb(jsv.nat), fnNatArb, fnNatArb, function(e, f, g) { | ||
return e.either(f, g) === f(e.value); | ||
})); | ||
}); | ||
it('returns the value of a Right after applying the second function arg', function() { | ||
jsv.assert(jsv.forall(rightArb(jsv.nat), fnNatArb, fnNatArb, function(e, f, g) { | ||
return e.either(f, g) === g(e.value); | ||
})); | ||
}); | ||
}); | ||
}); |
@@ -46,2 +46,14 @@ var R = require('ramda'); | ||
it('is a Semigroup', function() { | ||
var sTest = types.semigroup; | ||
// Inner type needs to be a semigroup. | ||
var s = MaybeArb(jsv.array(jsv.nat)); | ||
var s1 = MaybeArb(jsv.array(jsv.nat)); | ||
var s2 = MaybeArb(jsv.array(jsv.nat)); | ||
jsv.assert(jsv.forall(s, sTest.iface)); | ||
jsv.assert(jsv.forall(s, s1, s2, sTest.associative)); | ||
}); | ||
it('is a Functor', function() { | ||
@@ -103,3 +115,2 @@ var fTest = types.functor; | ||
}, 100000); | ||
console.log('a',a); | ||
assert.equal(true, Maybe.of('DONE').equals(a)); | ||
@@ -215,2 +226,15 @@ }); | ||
}); | ||
describe('#toMaybe', function() { | ||
it('produces a Nothing for null/undefined', function() { | ||
assert(Maybe.toMaybe(null).isNothing); | ||
assert(Maybe.toMaybe(void 0).isNothing); | ||
}); | ||
it('produces a Just for non-null values', function() { | ||
jsv.assert(jsv.forall(jsv.integer, function(n) { | ||
return Maybe.toMaybe(n).isJust; | ||
})); | ||
}); | ||
}); | ||
}); |
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
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
273733
53
4614
49
9
2
4