-
-
Notifications
You must be signed in to change notification settings - Fork 629
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
implement diff for map #2569
Comments
Hello @carnott-snap , do you know if there is |
I do not have experience with the scala stdlib, and was not aware vavr was tracking the scala stdlib. I just the need for this transform, and somebody commented that this exists in guava, so I started there. Do you think the feature has merit on its own, or is sticking to the scala api more important? |
I am probably not the right person to make the decision so I will let core maintainers to expression their ideas. Meanwhile, I hope the following code snippet could unblock you for map usage. (I never used Guava so I hope I didn't make any mistake): // Guava Maps#difference() equivalence in VAVR 1.0.0-alpha-3
Map<String, String> mapA = HashMap.of("a1", "1", "c1", "1", "c2", "2");
Map<String, String> mapB = HashMap.of("b1", "1", "c1", "1", "c2", "3");
// MapDifference#areEqual
boolean areEqual = mapA.equals(mapB);
assertThat(areEqual).isFalse();
assertThat(mapA.equals(HashMap.of("a1", "1", "c1", "1", "c2", "2"))).isTrue();
// MapDifference#entriesOnlyOnLeft
Map<String, String> entriesOnlyOnLeft = mapA.removeAll(mapB.keySet());
assertThat(entriesOnlyOnLeft).isEqualTo(HashMap.of("a1", "1"));
// MapDifference#entriesOnlyOnRight
Map<String, String> entriesOnlyOnRight = mapB.removeAll(mapA.keySet());
assertThat(entriesOnlyOnRight).isEqualTo(HashMap.of("b1", "1"));
// MapDifference#entriesInCommon
Map<String, String> entriesInCommon = mapA.retainAll(mapB);
assertThat(entriesInCommon).isEqualTo(HashMap.of("c1", "1"));
// MapDifference#entriesDiffering
// no, there is not... :/ |
slick, I was just going to use the guava logic and convert everything, but this is probably better. Plus I can just directly upstream the logic if that is the route you end up taking. Assuming we do, you think the interface should be like guava, where a complex object that can be interrogated is returned, or more building block methods like |
did this get implemented, or you are closing because it is stale? |
Yes, @mincong-h suggestion is the way to go. Java has mutable collections, so Guava's |
Set::diff is really helpful for calculating set difference, unfortunately, unlike Guava which has Maps.difference, there is nothing in Map.
The text was updated successfully, but these errors were encountered: