diff --git a/id.js b/id.js index e0e5cd4..a9c7e69 100644 --- a/id.js +++ b/id.js @@ -42,7 +42,7 @@ Id.prototype[fl.ap] = function(b) { // Traversable Id.prototype[fl.sequence] = function(of) { // the of argument is only provided for types where map might fail. - return this.value.map(Id[fl.of]); + return this.value[fl.map](Id[fl.of]); }; // Chain diff --git a/id_test.js b/id_test.js index 75f2eb4..c683584 100644 --- a/id_test.js +++ b/id_test.js @@ -32,10 +32,10 @@ Sum.prototype[concat] = function(x) { return Sum(this.v + x.v); }; Sum.prototype[equals] = function(x) { - return this.v.equals ? this.v.equals(x.v) : this.v === x.v; + return this.v[equals] ? this.v[equals](x.v) : this.v === x.v; }; -const equality = (x, y) => x.equals ? x.equals(y) : x === y; +const equality = (x, y) => x[equals] ? x[equals](y) : x === y; const test = f => t => { t.ok(f("x")); t.done(); @@ -59,7 +59,7 @@ exports.chainRec = { equivalence: test((x) => { var predicate = a => a.length > 5 var done = Id[of] - var next = a => Id[of](a.concat([x])) + var next = a => Id[of](a[concat]([x])) var initial = [x] return chainRec.equivalence(Id)(equality)(predicate)(done)(next)(initial) }) @@ -94,6 +94,9 @@ exports.monoid = { rightIdentity: test((x) => monoid.rightIdentity(Id[of](Sum[empty]()))(equality)(Sum[of](x))) }; +// Semigroup tests are broken otherwise for this. +String.prototype[concat] = String.prototype.concat + exports.semigroup = { associativity: test((x) => semigroup.associativity(Id[of])(equality)(x)) }; diff --git a/laws/chain.js b/laws/chain.js index 6ac8515..8044fd5 100644 --- a/laws/chain.js +++ b/laws/chain.js @@ -12,8 +12,8 @@ const {of, chain} = require('..'); const associativity = t => eq => x => { const a = t[of](x)[chain](t[of])[chain](t[of]); - const b = t[of](x)[chain]((x) => t[of](x).chain(t[of])); + const b = t[of](x)[chain]((x) => t[of](x)[chain](t[of])); return eq(a, b); }; -module.exports = { associativity }; \ No newline at end of file +module.exports = { associativity }; diff --git a/laws/semigroup.js b/laws/semigroup.js index 7f2da65..1b5f3bf 100644 --- a/laws/semigroup.js +++ b/laws/semigroup.js @@ -21,4 +21,4 @@ const associativity = t => eq => x => { return eq(a, b); }; -module.exports = { associativity }; \ No newline at end of file +module.exports = { associativity }; diff --git a/laws/traversable.js b/laws/traversable.js index 409d48d..53177e4 100644 --- a/laws/traversable.js +++ b/laws/traversable.js @@ -2,7 +2,7 @@ const Id = require('../id'); const {identity} = require('fantasy-combinators'); -const {of, ap, sequence, map, equals, empty, concat} = require('..'); +const {of, ap, reduce, sequence, map, equals, empty, concat} = require('..'); const {tagged} = require('daggy'); const Compose = tagged('c');