Skip to content

Commit

Permalink
Unbreak things (#157)
Browse files Browse the repository at this point in the history
  • Loading branch information
Isiah Meadows authored and SimonRichardson committed Sep 12, 2016
1 parent 831176f commit d1a3ee6
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion id.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions id_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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)
})
Expand Down Expand Up @@ -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))
};
Expand Down
4 changes: 2 additions & 2 deletions laws/chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
module.exports = { associativity };
2 changes: 1 addition & 1 deletion laws/semigroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ const associativity = t => eq => x => {
return eq(a, b);
};

module.exports = { associativity };
module.exports = { associativity };
2 changes: 1 addition & 1 deletion laws/traversable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit d1a3ee6

Please sign in to comment.