Skip to content

Commit

Permalink
Update TypeClass.test to respect constraints
Browse files Browse the repository at this point in the history
  • Loading branch information
Avaq authored and davidchambers committed Apr 21, 2021
1 parent 45153fb commit b51561e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
22 changes: 13 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@
(function() {
var $seen = [];
return function(x) {
// if ($seen.includes (x)) return true;
if ($seen.includes (x)) return true;

$seen.push (x);
try {
Expand Down Expand Up @@ -768,7 +768,7 @@
return [];
}

// Array$prototype$equals :: Array a ~> Array a -> Boolean
// Array$prototype$equals :: Setoid a => Array a ~> Array a -> Boolean
function Array$prototype$equals(other) {
if (other.length !== this.length) return false;
for (var idx = 0; idx < this.length; idx += 1) {
Expand All @@ -777,7 +777,7 @@
return true;
}

// Array$prototype$lte :: Array a ~> Array a -> Boolean
// Array$prototype$lte :: Ord a => Array a ~> Array a -> Boolean
function Array$prototype$lte(other) {
for (var idx = 0; true; idx += 1) {
if (idx === this.length) return true;
Expand Down Expand Up @@ -883,15 +883,15 @@
return {};
}

// Object$prototype$equals :: StrMap a ~> StrMap a -> Boolean
// Object$prototype$equals :: Setoid a => StrMap a ~> StrMap a -> Boolean
function Object$prototype$equals(other) {
var self = this;
var keys = sortedKeys (this);
return equals (keys, sortedKeys (other)) &&
keys.every (function(k) { return equals (self[k], other[k]); });
}

// Object$prototype$lte :: StrMap a ~> StrMap a -> Boolean
// Object$prototype$lte :: Ord a => StrMap a ~> StrMap a -> Boolean
function Object$prototype$lte(other) {
var theseKeys = sortedKeys (this);
var otherKeys = sortedKeys (other);
Expand Down Expand Up @@ -1092,9 +1092,9 @@
case 'String#fantasy-land/concat':
return String$prototype$concat;
case 'Array#fantasy-land/equals':
return Array$prototype$equals;
return value.every (Setoid.test) ? Array$prototype$equals : null;
case 'Array#fantasy-land/lte':
return Array$prototype$lte;
return value.every (Ord.test) ? Array$prototype$lte : null;
case 'Array#fantasy-land/concat':
return Array$prototype$concat;
case 'Array#fantasy-land/filter':
Expand All @@ -1120,9 +1120,13 @@
case 'Error#fantasy-land/equals':
return Error$prototype$equals;
case 'Object#fantasy-land/equals':
return Object$prototype$equals;
return (Object.values (value)).every (Setoid.test) ?
Object$prototype$equals :
null;
case 'Object#fantasy-land/lte':
return Object$prototype$lte;
return (Object.values (value)).every (Ord.test) ?
Object$prototype$lte :
null;
case 'Object#fantasy-land/concat':
return Object$prototype$concat;
case 'Object#fantasy-land/filter':
Expand Down
4 changes: 4 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,8 @@ test ('Setoid', function() {
eq (Z.Setoid.test ([]), true);
eq (Z.Setoid.test ({}), true);
eq (Z.Setoid.test (Useless), false);
eq (Z.Setoid.test ([Useless]), false);
eq (Z.Setoid.test ({foo: Useless}), false);
});

test ('Ord', function() {
Expand All @@ -334,6 +336,8 @@ test ('Ord', function() {
eq (Z.Ord.test ([]), true);
eq (Z.Ord.test ({}), true);
eq (Z.Ord.test (Math.abs), false);
eq (Z.Ord.test ([Math.abs]), false);
eq (Z.Ord.test ({foo: Math.abs}), false);
});

test ('Semigroupoid', function() {
Expand Down

0 comments on commit b51561e

Please sign in to comment.