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

Fix issue with use of "root" uncons / uncons1 and clarify docs #808

Merged
merged 2 commits into from
Feb 10, 2017

Conversation

pchiusano
Copy link
Contributor

I was looking into clarifying the docs on uncons and uncons1 to say that they should be used in conjunction with Stream.scope (see #797) and noticed what I'd say is a problem - if you use uncons but don't have a surrounding scope call or Pull (which uses scope), you can have a finalizer not run. This test used to fail:

    "early termination of uncons" in {
      var n = 0
      Stream(1,2,3).onFinalize(Task.delay(n = 1)).uncons.run.unsafeRun
      n shouldBe 1
    }

That test is now fixed, by adding a call to scope in runFold, but the note about using scope in conjunction with uncons still applies if you want prompt finalization.

Sorry @jedesah but my docs kind of clobber some of your work in #797. I felt like the docs were trying to cover too many things (like the fact that if you reference an effectful stream twice, its effects are repeated... which is not really specific to uncons at all, just a general property of effectful streams).

This could be backported to 0.9 series also? Not sure how important that is, this would only show up if you were using uncons at the "root" of your stream, which I think would be super rare.

…n even if uncons is used without an enclosing user-provided scope
@mpilquist mpilquist merged commit 3bb2616 into series/1.0 Feb 10, 2017
@jedesah
Copy link
Contributor

jedesah commented Feb 10, 2017

As much as it's kind of neat to show that you can implement take with uncons, I don't think it's the best example as it doesn't really show what uncons is typically useful for. Perhaps my mapFirstN was a little odd I'll admit. I find a common use case for uncons is doing some kind of sneak peak on a Stream before deciding exactly how to process the remainder of it. Perhaps an example in that vein would meet everyone's approval?

@pchiusano I agree that referencing an effectful Stream twice is a general problem, however uncons seems to often be the solution to achieve what is desired in a proper way. I'll admit I have not fully wrapped my head around the differences between fs2 and scalaz-stream and perhaps uncons is no longer a particularly common solution to that problem. Perhaps this common pitfall should be documented somewhere else at the very least.

@pchiusano
Copy link
Contributor Author

pchiusano commented Feb 10, 2017 via email

@jedesah
Copy link
Contributor

jedesah commented Feb 13, 2017

@pchiusano Sure I think what you said makes sense. I'll take a crack at it.

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.

3 participants