-
Notifications
You must be signed in to change notification settings - Fork 448
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CU-ev2g8f Fix Sequence#travserse, Option#apEval & Either#apEval #2260
Conversation
Task linked: CU-ev2g8f Fix Sequence#traverse |
@@ -1588,7 +1588,7 @@ fun <A, B, C> EitherOf<A, B>.ap(ff: EitherOf<A, (B) -> C>): Either<A, C> = | |||
flatMap { a -> ff.fix().map { f -> f(a) } } | |||
|
|||
fun <A, B, C> Either<A, B>.apEval(ff: Eval<Either<A, (B) -> C>>): Eval<Either<A, C>> = | |||
ff.map { this.ap(it) } | |||
fold({ l -> Eval.now(l.left()) }, { r -> ff.map { it.map { f -> f(r) } } }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there or should be a specific test for this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should add many tests.. 😭😅 This code was taken from the EitherApply.kt
code, and is verified in TraverseTest
. By reverting this change it makes TraverseTest
fail.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By reverting this change it makes TraverseTest fail.
That's what I meant, perfect then! 👌
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks @nomisRev
This PR fixes two issues for traversing an
Sequence
.foldRight
withoutEval
which first materialises the whole list in memory. This always results in anOOM
even if the transformation oftraverse
results in a short-circuit.apEval
forEither
andOption
to properly short-circuit.