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

Foldable[Stream].foldRight isn't stack-safe #828

Closed
ceedubs opened this issue Jan 26, 2016 · 1 comment
Closed

Foldable[Stream].foldRight isn't stack-safe #828

ceedubs opened this issue Jan 26, 2016 · 1 comment
Labels

Comments

@ceedubs
Copy link
Contributor

ceedubs commented Jan 26, 2016

The following code results in a stack overflow, but it should return false, because this is basically how forall is implemented in Foldable.

import cats._, cats.implicits._

val s: Stream[Boolean] = Stream.fill(10000)(true) ++ Stream.continually(false)

Foldable[Stream].foldRight(s, Eval.now(true))((a,b) => if (a) b else Eval.now(false)).value

Notably, Foldable[Stream].forall is actually stack-safe, but that's because it is overridden to use Stream.forall.

I noticed this when looking at #824.

@ceedubs ceedubs added the bug label Jan 26, 2016
ceedubs added a commit to ceedubs/cats that referenced this issue Jan 30, 2016
Resolves typelevel#828. I can't reproduce the behavior that I reported in that
issue. I'm not sure why I had trouble at first - maybe I was using
`Stream.foldRight` instead of `Foldable[Stream].foldRight`? I don't
think I was though, so this is a bit odd to me.
@ceedubs
Copy link
Contributor Author

ceedubs commented Jan 30, 2016

Actually, I can't reproduce this, and it looks like we already have a test for this in FoldableStreamCheck. Maybe I was using .foldRight on a Stream instead of using the Foldable instance? I'm not sure. I'm going to go ahead and close this out.

@ceedubs ceedubs closed this as completed Jan 30, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant