Skip to content

Commit

Permalink
whoops, intersection of iterable returned always empty set
Browse files Browse the repository at this point in the history
  • Loading branch information
jyrimatti committed Sep 17, 2024
1 parent 53f16de commit 77f2d51
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>fi.solita.utils</groupId>
<artifactId>functional-utils</artifactId>
<version>0.12.53</version>
<version>0.12.54</version>
<build>
<resources>
<resource>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/fi/solita/utils/functional/FunctionalS.java
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ public static final <T> Set<T> intersection(Set<T> e1, Set<T> e2, Set<T> e3, Set
* @return Set intersection of Sets in {@code es}.
*/
public static final <T> Set<T> intersection(Iterable<? extends Set<T>> es) {
return FunctionalImpl.fold(Collections.<T>emptySet(), SemiGroups.<T>setIntersection(), es);
return FunctionalImpl.fold(SemiGroups.<T>setIntersection(), es).getOrElse(Collections.<T>emptySet());
}


Expand Down
11 changes: 11 additions & 0 deletions src/test/java/fi/solita/utils/functional/FunctionalTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package fi.solita.utils.functional;
import static fi.solita.utils.functional.Collections.emptyList;
import static fi.solita.utils.functional.Collections.emptySet;
import static fi.solita.utils.functional.Collections.newList;
import static fi.solita.utils.functional.Collections.newMutableList;
import static fi.solita.utils.functional.Collections.newSet;
Expand Down Expand Up @@ -412,4 +413,14 @@ public void padRight() {
assertEquals("xx", Functional.padRight(2, '0', "xx").toString());
assertEquals("xxx", Functional.padRight(2, '0', "xxx").toString());
}

@Test
public void testIntersection() {
assertEquals(emptySet(), Functional.intersection(Collections.<Integer>emptySet(), newSet(2,3)));
assertEquals(emptySet(), Functional.intersection(newSet(2,3), Collections.<Integer>emptySet()));
assertEquals(emptySet(), Functional.intersection(Arrays.asList(Collections.<Integer>emptySet(), newSet(2,3))));

assertEquals(newSet(2), Functional.intersection(newSet(1,2), newSet(2,3)));
assertEquals(newSet(2), Functional.intersection(Arrays.asList(newSet(1,2), newSet(2,3))));
}
}

0 comments on commit 77f2d51

Please sign in to comment.