Skip to content

Commit

Permalink
reduce: don't execute function for collections of size 1
Browse files Browse the repository at this point in the history
  • Loading branch information
jyrimatti committed Dec 10, 2024
1 parent 4ec981c commit 7d3f49c
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ static final <T extends SemiGroup<T>> Option<T> reduce(Iterable<? extends T> xs)
}

static final <T> T reduce(Monoid<T> monoid, Iterable<? extends T> xs) {
return xs == null ? null : fold(monoid, cons(monoid.zero(), xs)).get();
return fold(monoid, xs).getOrElse(monoid.zero());
}

static final <T,Z> Z fold(Z zero, Apply<Map.Entry<? extends Z,? extends T>, Z> f, Iterable<? extends T> xs) {
Expand Down

0 comments on commit 7d3f49c

Please sign in to comment.