-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Add Apply.map2Eval and allow traverse laziness #1015
Conversation
Fixes typelevel#513. I think this should solve the majority of use-cases for lazy traversal. One thing I noticed is that both `reduceRightToOption` and `traverse1_` (which uses the former) seem to be impossible to implement lazily such that they allow for short-circuiting. At least I couldn't figure out a way. I left a note in the `traverse1_` scaladoc, but in practice I don't anticipate this being a problem, because at the cost of just having an `Applicative` instance as opposed to `Apply`, you can use `traverse_` which is sufficiently lazy.
Another note: it kind of seems like there should be things like |
@julien-truffaut would you want to review this since you originally opened up #513? |
👍 |
foldLeft(fa, G.pure(())) { (acc, a) => | ||
G.map2(acc, f(a)) { (_, _) => () } | ||
} | ||
foldRight(fa, Later(G.pure(()))) { (a, acc) => |
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.
You might want to use Always
here, since it will be evaluated once and there's no need for memoization.
This avoids a bit of memoization overhead in places that we only expect to be evaluated once.
Current coverage is 82.23%
@@ master #1015 diff @@
==========================================
Files 215 215
Lines 2704 2713 +9
Methods 2639 2647 +8
Messages 0 0
Branches 60 61 +1
==========================================
+ Hits 2217 2231 +14
+ Misses 487 482 -5
Partials 0 0
|
👍 |
1 similar comment
👍 |
This adds a test case that the `traverse` implementation for `Vector` short-circuits the traversal when possible. This would have failed the build in typelevel#2091. See typelevel#1015 for when similar tests were added for similar structures.
Fixes #513.
I think this should solve the majority of use-cases for lazy traversal.
One thing I noticed is that both
reduceRightToOption
andtraverse1_
(which uses the former) seem to be impossible to implement lazily such
that they allow for short-circuiting. At least I couldn't figure out a
way. I left a note in the
traverse1_
scaladoc, but in practice I don'tanticipate this being a problem, because at the cost of just having an
Applicative
instance as opposed toApply
, you can usetraverse_
which is sufficiently lazy.