-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix some issues with value equality #32
Conversation
This fixes an issue where two equivalent instances of Json are not considered equal, because after JSON.stringifying the input object, the key order is taken into account when considering equality.
}); | ||
|
||
test ('Json', () => { | ||
eq (lib.Response.is (lib.Json (null)), true); | ||
eq (lib.Json (null), lib.Json (null)); | ||
eq (lib.Json ({a: 1, b: 2}), lib.Json ({b: 2, a: 1})); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This assertion would fail, previously, because of the key order.
Codecov Report
@@ Coverage Diff @@
## master #32 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 1 1
Lines 461 478 +17
=========================================
+ Hits 461 478 +17
Continue to review full report at Codecov.
|
This function can be (and will be) used more generally to match against a subset of tags, with each of the other tags resulting in the provided default value.
2ada9c3
to
7fcb535
Compare
@@ -244,16 +262,15 @@ export const Text = value => Response.Respond ( | |||
Body.Send (value), | |||
); | |||
|
|||
//# Json :: Object -> Response a b | |||
//# Json :: JsonValue -> Response a b |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does JsonValue mean something like any JSON-serializable data?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah. Not all values of type Object are valid input here.
index.js
Outdated
return this.cata ({ | ||
None: _ => cataBool ({None: _ => true}) (other), | ||
Send: a => cataBool ({Send: b => Z.equals (a, b)}) (other), | ||
Json: a => cataBool ({Json: b => Z.equals (a, b)}) (other), | ||
Stream: a => cataBool ({Stream: b => a === b}) (other), | ||
Render: (...a) => cataBool ({Render: (...b) => Z.equals (a, b)}) (other), | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could avoid repeating (other)
:
return this.cata ({
// ...
}) (other);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, yes. Nifty. :)
This commit fixes an issue where two equivalent values of type Stream are not considered equal. This happens because the inner value of a Stream (a Future) does not implement Setoid. We fix this by using reference equality.
While updating to 5.0 I found my tests' assertions started failing for some of the Json values. These fixes should address that, and similar, problems.