Implement Zipper Eq and Hash and add tests#343
Conversation
Codecov Report
@@ Coverage Diff @@
## master #343 +/- ##
==========================================
- Coverage 41.49% 40.95% -0.55%
==========================================
Files 176 176
Lines 9174 9189 +15
Branches 522 524 +2
==========================================
- Hits 3807 3763 -44
- Misses 5217 5264 +47
- Partials 150 162 +12
Continue to review full report at Codecov.
|
| Zipper<A> x1 = a1; | ||
| Zipper<A> x2 = a2; | ||
|
|
||
| x1.move(0); |
There was a problem hiding this comment.
those two move(0) statements do nothing?
There was a problem hiding this comment.
The zipper handed out might not be focus at start. Let me know if you think they are not needed.
There was a problem hiding this comment.
but move is a pure function so you must use the result if you want to do that.
But probably the position of a zipper is important and I'd be in favor of just comparing lefts(), focus() and right(). This is also what the haskell implementations I have seen do.
There was a problem hiding this comment.
thanks for the pointer. updated
| int r = 239; | ||
| Zipper<A> aas = as; | ||
|
|
||
| aas.move(0); |
There was a problem hiding this comment.
The zipper handed out might not be focus at start. Let me know if you think they are not needed.
There was a problem hiding this comment.
Same as for Equal, I'd say we just need to combine the hash of lefts(), focus() and right().
| public static <A> Equal<Zipper<A>> zipperEqual(final Equal<A> ea) { | ||
| Definition<A> eaDef = ea.def; | ||
| return equalDef((a1, a2) -> { | ||
| return Equal.equals0(Stream.class, a1.lefts(), a2.lefts(), () -> Equal.streamEqual(Equal.anyEqual())) && |
There was a problem hiding this comment.
I think streamEqual should use Equal<A> not anyEqual. also It would be best to save the streamEqual in a local variable for reuse.
Also equals0need to be used.
There was a problem hiding this comment.
partially updated. I'm not sure about equals0
| final int p = 419; | ||
| int r = 239; | ||
|
|
||
| r = p * r + streamHash(ha).hash(as.lefts()); |
There was a problem hiding this comment.
also probably best to save streamHash(ha) in a local variable.
Signed-off-by: Gábor Lipták <gliptak@gmail.com>
|
thank you for the update. squashed. |
Signed-off-by: Gábor Lipták gliptak@gmail.com