Skip to content
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

Merged
merged 6 commits into from
Feb 26, 2021

Conversation

nomisRev
Copy link
Member

This PR fixes two issues for traversing an Sequence.

  • Sequence#traverse was implemented using foldRight without Eval which first materialises the whole list in memory. This always results in an OOM even if the transformation of traverse results in a short-circuit.
  • Fix apEval for Either and Option to properly short-circuit.

@nomisRev nomisRev requested review from 1Jajen1 and a team February 25, 2021 14:32
@franciscodr
Copy link
Collaborator

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) } } })
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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! 👌

Copy link
Member

@i-walker i-walker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you

Copy link
Member

@raulraja raulraja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @nomisRev

@nomisRev nomisRev merged commit 3bee3c0 into master Feb 26, 2021
@nomisRev nomisRev deleted the cu-ev2g8f-fix-sequence-travserse branch February 26, 2021 10:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants