palatable / lambda

Functional patterns for Java
https://palatable.github.io/lambda/
MIT License
864 stars 85 forks source link

FoldRight fixes for Monoid/Semigroup #128

Closed 7h3kk1d closed 1 year ago

7h3kk1d commented 1 year ago

Addressing https://github.com/palatable/lambda/issues/127

Sidenote Monoid::foldMap seems to be where short-circuiting is currently implemented. Something that was going to be addressed in the incomplete https://github.com/palatable/lambda/pull/122/files. For obvious reasons, it doesn't seem to address semigroups that should short-circuit. In addition, it has some odd behavior for Monoid::foldRight. For example the function application will now match Semigroup::foldRight, but and().foldRight(true, repeat(false)).value() does not short circuit with the current implementation of Monoid::foldRight. I'm tempted to remove foldLeft/foldRight from Monoid and add a lazilyApply to Semigroup that would allow for users to override for short-circuiting behavior.