This API is still experimental, so it may change or be removed in future versions. You should not rely on it for production applications.
(('a, 'a) => Boolean) => (Variant, Union) => Void
(valuesEqual) => {
/*~
* type: ('a, 'a) => Boolean
*/
const equals = (a, b) => {
// identical objects must be equal
if (a === b) return true;
// we require both values to be setoids if one of them is
const leftSetoid = isSetoid(a);
const rightSetoid = isSetoid(b);
if (leftSetoid) {
if (rightSetoid) return flEquals(a, b);
else return false;
}
// fall back to the provided equality
return valuesEqual(a, b);
};
/*~
* type: (Object Any, Object Any, Array String) => Boolean
*/
const compositesEqual = (a, b, keys) => {
for (let i = 0; i < keys.length; ++i) {
const keyA = a[keys[i]];
const keyB = b[keys[i]];
if (!(equals(keyA, keyB))) {
return false;
}
}
return true;
};
const derivation = (variant, adt) => {
/*~
* stability: experimental
* module: null
* authors:
* - "@boris-marinov"
* - Quildreen Motta
*
* type: |
* forall S, a:
* (S a).(S a) => Boolean
* where S is Setoid
*/
variant.prototype.equals = function(value) {
assertType(adt)(`${this[tagSymbol]}#equals`, value);
return sameType(this, value) && compositesEqual(this, value, Object.keys(this));
};
provideAliases(variant.prototype);
return variant;
};
copyDocs(createDerivation, derivation, {
type: '(Variant, Union) => Void'
});
return derivation;
}