Skip to content

Commit

Permalink
update static method lookup to match prototype method lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
davidchambers committed Apr 21, 2021
1 parent 5355a03 commit 432622b
Showing 1 changed file with 28 additions and 18 deletions.
46 changes: 28 additions & 18 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@
typeRep != null && typeof typeRep[name] === 'function' ?
typeRep[name] :
typeof typeRep === 'function' ?
implementations[functionName (typeRep) + '.' + name] :
staticMethod (name, typeRep) :
// else
null
);
Expand All @@ -265,7 +265,7 @@
typeof x[name] === 'function' ?
x[name] :
// else
implementation (name, x)
prototypeMethod (name, x)
);
};
}
Expand Down Expand Up @@ -1034,7 +1034,32 @@
return function(x) { return contravariant (f (x)); };
}

function implementation(name, value) {
function staticMethod(name, typeRep) {
switch (functionName (typeRep) + '.' + name) {
case 'String.fantasy-land/empty':
return String$empty;
case 'Array.fantasy-land/empty':
return Array$empty;
case 'Array.fantasy-land/of':
return Array$of;
case 'Array.fantasy-land/chainRec':
return Array$chainRec;
case 'Array.fantasy-land/zero':
return Array$zero;
case 'Object.fantasy-land/empty':
return Object$empty;
case 'Object.fantasy-land/zero':
return Object$zero;
case 'Function.fantasy-land/id':
return Function$id;
case 'Function.fantasy-land/of':
return Function$of;
case 'Function.fantasy-land/chainRec':
return Function$chainRec;
}
}

function prototypeMethod(name, value) {
switch (type (value) + '#' + name) {
case 'Null#fantasy-land/equals':
return Null$prototype$equals;
Expand Down Expand Up @@ -1135,21 +1160,6 @@
}
}

/* eslint-disable key-spacing */
var implementations = {
'String.fantasy-land/empty': String$empty,
'Array.fantasy-land/empty': Array$empty,
'Array.fantasy-land/of': Array$of,
'Array.fantasy-land/chainRec': Array$chainRec,
'Array.fantasy-land/zero': Array$zero,
'Object.fantasy-land/empty': Object$empty,
'Object.fantasy-land/zero': Object$zero,
'Function.fantasy-land/id': Function$id,
'Function.fantasy-land/of': Function$of,
'Function.fantasy-land/chainRec': Function$chainRec
};
/* eslint-enable key-spacing */

//# equals :: (a, b) -> Boolean
//.
//. Returns `true` if its arguments are of the same type and equal according
Expand Down

0 comments on commit 432622b

Please sign in to comment.