fantasy-land
Advanced tools
Comparing version 2.0.0 to 2.1.0
@@ -15,2 +15,4 @@ (function() { | ||
of: 'fantasy-land/of', | ||
alt: 'fantasy-land/alt', | ||
zero: 'fantasy-land/zero', | ||
reduce: 'fantasy-land/reduce', | ||
@@ -17,0 +19,0 @@ traverse: 'fantasy-land/traverse', |
@@ -20,3 +20,3 @@ 'use strict'; | ||
const composition = of => eq => x => f => g => { | ||
const composition = of => eq => f => g => x => { | ||
const a = of(x)[map](x => f(g(x))); | ||
@@ -23,0 +23,0 @@ const b = of(x)[map](g)[map](f); |
@@ -9,8 +9,8 @@ 'use strict'; | ||
1. `m.of(a).chain(f)` is equivalent to `f(a)` (left identity) | ||
2. `m.chain(m.of)` is equivalent to `m` (right identity) | ||
1. `M.of(a).chain(f)` is equivalent to `f(a)` (left identity) | ||
2. `m.chain(M.of)` is equivalent to `m` (right identity) | ||
**/ | ||
const leftIdentity = t => eq => x => f => { | ||
const leftIdentity = t => eq => f => x => { | ||
const a = t[of](x)[chain](f); | ||
@@ -17,0 +17,0 @@ const b = f(x); |
@@ -9,4 +9,4 @@ 'use strict'; | ||
1. `m.concat(m.constructor.empty())` is equivalent to `m` (right identity) | ||
2. `m.constructor.empty().concat(m)` is equivalent to `m` (left identity) | ||
1. `m.concat(M.empty())` is equivalent to `m` (right identity) | ||
2. `M.empty().concat(m)` is equivalent to `m` (left identity) | ||
@@ -13,0 +13,0 @@ **/ |
'use strict'; | ||
const Id = require('../id'); | ||
const {Id, Compose} = require('../internal'); | ||
const {identity} = require('fantasy-combinators'); | ||
const {of, ap, reduce, traverse, map, equals, concat} = require('..'); | ||
const {tagged} = require('daggy'); | ||
const {of, traverse, map} = require('..'); | ||
const Compose = tagged('c'); | ||
Compose[of] = Compose; | ||
Compose.prototype[ap] = function(f) { | ||
return Compose(this.c[ap](f.c[map](u => y => y[ap](u)))); | ||
}; | ||
Compose.prototype[map] = function(f) { | ||
return Compose(this.c[map](y => y[map](f))); | ||
}; | ||
Compose.prototype[equals] = function(x) { | ||
return this.c[equals] ? this.c[equals](x.c) : this.c === x.c; | ||
}; | ||
Array.prototype[equals] = function(y) { | ||
return this.length === y.length && this.join('') === y.join(''); | ||
}; | ||
Array.prototype[map] = Array.prototype.map; | ||
Array.prototype[reduce] = Array.prototype.reduce; | ||
Array.prototype[concat] = Array.prototype.concat; | ||
Array.prototype[traverse] = function(f, p) { | ||
return this.map(f)[reduce]( | ||
(ys, x) => ys[ap](x[map](y => z => z[concat](y))), | ||
p([]) | ||
); | ||
}; | ||
/** | ||
@@ -34,0 +8,0 @@ |
{ | ||
"name": "fantasy-land", | ||
"author": "Brian McKenna", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "Specification for interoperability of common algebraic structures in JavaScript", | ||
@@ -36,4 +36,4 @@ "license": "MIT", | ||
"files": [ | ||
"id.js", | ||
"index.js", | ||
"internal/*.js", | ||
"laws/*.js" | ||
@@ -43,4 +43,5 @@ ], | ||
"scripts": { | ||
"lint": "eslint --config node_modules/sanctuary-style/eslint-es6.json --env es6 --env node --rule 'max-len: [off]' -- *.js laws/*.js", | ||
"test": "npm run-script lint && nodeunit id_test.js", | ||
"lint": "eslint --config node_modules/sanctuary-style/eslint-es6.json --env es6 --env node --rule 'max-len: [off]' -- *.js laws/*.js internal/*.js", | ||
"unit": "nodeunit test.js", | ||
"test": "npm run-script lint && npm run-script unit", | ||
"release-major": "xyz --repo git@github.com:fantasyland/fantasy-land.git --increment major", | ||
@@ -47,0 +48,0 @@ "release-minor": "xyz --repo git@github.com:fantasyland/fantasy-land.git --increment minor", |
@@ -18,2 +18,5 @@ # Fantasy Land Specification | ||
* [Applicative](#applicative) | ||
* [Alt](#alt) | ||
* [Plus](#plus) | ||
* [Alternative](#alternative) | ||
* [Foldable](#foldable) | ||
@@ -29,3 +32,3 @@ * [Traversable](#traversable) | ||
<img src="figures/dependencies.png" width="863" height="347" /> | ||
<img src="figures/dependencies.png" width="888" height="340" /> | ||
@@ -142,4 +145,4 @@ ## General | ||
1. `m.concat(m.constructor.empty())` is equivalent to `m` (right identity) | ||
2. `m.constructor.empty().concat(m)` is equivalent to `m` (left identity) | ||
1. `m.concat(M.empty())` is equivalent to `m` (right identity) | ||
2. `M.empty().concat(m)` is equivalent to `m` (left identity) | ||
@@ -249,2 +252,65 @@ #### `empty` method | ||
### Alt | ||
A value that implements the Alt specification must also implement | ||
the [Functor](#functor) specification. | ||
1. `a.alt(b).alt(c)` is equivalent to `a.alt(b.alt(c))` (associativity) | ||
2. `a.alt(b).map(f)` is equivalent to `a.map(f).alt(b.map(f))` (distributivity) | ||
#### `alt` method | ||
```hs | ||
alt :: Alt f => f a ~> f a -> f a | ||
``` | ||
A value which has a Alt must provide a `alt` method. The | ||
`alt` method takes one argument: | ||
a.alt(b) | ||
1. `b` must be a value of the same Alt | ||
1. If `b` is not the same Alt, behaviour of `alt` is | ||
unspecified. | ||
2. `a` and `b` can contain any value of same type. | ||
3. No parts of `a`'s and `b`'s containing value should be checked. | ||
2. `alt` must return a value of the same Alt. | ||
### Plus | ||
A value that implements the Plus specification must also implement | ||
the [Alt](#alt) specification. | ||
1. `x.alt(A.zero())` is equivalent to `x` (right identity) | ||
2. `A.zero().alt(x)` is equivalent to `x` (left identity) | ||
2. `A.zero().map(f)` is equivalent to `A.zero()` (annihilation) | ||
#### `zero` method | ||
```hs | ||
zero :: Plus f => () -> f a | ||
``` | ||
A value which has a Plus must provide an `zero` function on its | ||
[type representative](#type-representatives): | ||
A.zero() | ||
Given a value `x`, one can access its type representative via the | ||
`constructor` property: | ||
x.constructor.zero() | ||
1. `zero` must return a value of the same Plus | ||
### Alternative | ||
A value that implements the Alternative specification must also implement | ||
the [Applicative](#applicative) and [Plus](#plus) specifications. | ||
1. `x.ap(f.alt(g))` is equivalent to `x.ap(f).alt(x.ap(g))` (distributivity) | ||
1. `x.ap(A.zero())` is equivalent to `A.zero()` (annihilation) | ||
### Foldable | ||
@@ -393,4 +459,4 @@ | ||
1. `m.of(a).chain(f)` is equivalent to `f(a)` (left identity) | ||
2. `m.chain(m.of)` is equivalent to `m` (right identity) | ||
1. `M.of(a).chain(f)` is equivalent to `f(a)` (left identity) | ||
2. `m.chain(M.of)` is equivalent to `m` (right identity) | ||
@@ -597,3 +663,3 @@ ### Extend | ||
4. An `Id` container which implements many of the methods is provided in | ||
`id.js`. | ||
`internal/id.js`. | ||
@@ -600,0 +666,0 @@ |
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
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
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
36628
28
504
679
0