Skip to content

Commit 3fe3639

Browse files
7h3kk1dSkylerLutz
andauthored
Fix Absent::foldLeft bug (#121)
Co-authored-by: Alexander Bandukwala <[email protected]> Co-authored-by: Skyler Lutz <[email protected]>
1 parent f66ec60 commit 3fe3639

File tree

2 files changed

+8
-1
lines changed
  • src
    • main/java/com/jnape/palatable/lambda/semigroup/builtin
    • test/java/com/jnape/palatable/lambda/semigroup/builtin

2 files changed

+8
-1
lines changed

src/main/java/com/jnape/palatable/lambda/semigroup/builtin/Absent.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public Maybe<A> checkedApply(Maybe<A> maybeX, Maybe<A> maybeY) {
7272
@Override
7373
public Maybe<A> foldLeft(Maybe<A> acc, Iterable<Maybe<A>> maybes) {
7474
return trampoline(
75-
into((res, it) -> res.equals(nothing())
75+
into((res, it) -> res.equals(nothing()) || !it.hasNext()
7676
? terminate(res)
7777
: recurse(tuple(liftA2(aSemigroup, res, it.next()), it))),
7878
tuple(acc, maybes.iterator()));

src/test/java/com/jnape/palatable/lambda/semigroup/builtin/AbsentTest.java

+7
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,13 @@ public void foldLeftShortCircuit() {
7171
assertEquals(nothing(), result);
7272
}
7373

74+
@Test
75+
public void foldLeftWorksForJusts() {
76+
Maybe<Unit> result = Absent.<Unit>absent(Constantly::constantly)
77+
.foldLeft(just(UNIT), Arrays.asList(just(UNIT), just(UNIT)));
78+
assertEquals(just(UNIT), result);
79+
}
80+
7481
@Test(timeout = 200)
7582
public void checkedApplyFoldRightShortCircuit() {
7683
Maybe<Unit> result = Absent.<Unit>absent().checkedApply(Constantly::constantly)

0 commit comments

Comments
 (0)