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

Make traverse lazy #513

Closed
julien-truffaut opened this issue Sep 2, 2015 · 4 comments
Closed

Make traverse lazy #513

julien-truffaut opened this issue Sep 2, 2015 · 4 comments
Assignees
Milestone

Comments

@julien-truffaut
Copy link
Contributor

I believe we can make traverse lazy by using thunk or Eval in Applicative.map2 (please correct me if I am wrong)

def validate(i: Int): Option[Int] = if(i < 5) Some(i) else None

List(1,2,6,8).traverse(validate) // should not evaluate validate(8)
@ceedubs
Copy link
Contributor

ceedubs commented Sep 6, 2015

Yes, I believe this is the case, and I would vote 👍 for this happening. The question is where exactly it would need to go, since map2 is defined in terms of ap and map. I think in the current state of things, it would need to go in ap. @non how does this relate to the monoidal work you've been doing?

@ceedubs ceedubs added this to the cats-1.0.0 milestone Nov 10, 2015
@ceedubs
Copy link
Contributor

ceedubs commented Jan 30, 2016

I think that now that Cartesian is in place, we should revisit this.

@ceedubs
Copy link
Contributor

ceedubs commented Apr 24, 2016

I'm working on this.

@ceedubs
Copy link
Contributor

ceedubs commented Apr 27, 2016

I have a good start on this in a local branch, but this week got busy. I'm hoping to submit a PR next week.

ceedubs added a commit to ceedubs/cats that referenced this issue May 4, 2016
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.
ceedubs added a commit to ceedubs/cats that referenced this issue May 4, 2016
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.
ceedubs added a commit to ceedubs/cats that referenced this issue May 4, 2016
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.
@ceedubs ceedubs self-assigned this May 4, 2016
@stew stew removed the in progress label May 11, 2016
travisbrown added a commit to travisbrown/cats that referenced this issue Aug 22, 2019
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

No branches or pull requests

3 participants