Skip to content

Commit f762bf3

Browse files
committed
#64: Fixed adding items to the immutable tree map
1 parent 94195af commit f762bf3

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

core/src/main/java/fj/data/List.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,10 +1333,9 @@ public final <B, C, D> TreeMap<B, D> groupBy(
13331333
return this.foldLeft(map -> element -> {
13341334
final B key = keyFunction.f(element);
13351335
final C value = valueFunction.f(element);
1336-
map.set(key, map.get(key)
1336+
return map.set(key, map.get(key)
13371337
.map(existing -> groupingAcc.f(value, existing))
13381338
.orSome(groupingAcc.f(value, groupingIdentity)));
1339-
return map;
13401339
}, TreeMap.<B, D>empty(keyOrd)
13411340
);
13421341
}

tests/src/test/scala/fj/data/CheckList.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,8 @@ object CheckList extends Properties("List") {
180180
property("groupBy") = forAll((a: List[Int]) => {
181181
val result = a.groupBy((x: Int) => (x % 2 == 0): lang.Boolean)
182182
result.get(true).forall((xs: List[Int]) => xs.forall((x: Int) => (x % 2 == 0): lang.Boolean): lang.Boolean) &&
183-
result.get(false).forall((xs: List[Int]) => xs.forall((x: Int) => (x % 2 != 0): lang.Boolean): lang.Boolean)
183+
result.get(false).forall((xs: List[Int]) => xs.forall((x: Int) => (x % 2 != 0): lang.Boolean): lang.Boolean) &&
184+
a.map((x: Int) => (x % 2) == 0: lang.Boolean).nub().length() == result.size()
184185
})
185186

186187
property("groupByMonoid") = forAll((a: List[Int]) => {

0 commit comments

Comments
 (0)