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

Don't buffer stream inside of toString() #259

Open
lukaseder opened this issue Sep 7, 2016 · 9 comments
Open

Don't buffer stream inside of toString() #259

lukaseder opened this issue Sep 7, 2016 · 9 comments

Comments

@lukaseder
Copy link
Member

Seq currently buffers any stream when calling toString() because this allows for a nice display in debuggers without wasting the stream / modifying program behaviour.

However, buffering the stream has side effects, mainly also when debugging, breakpoints inside of a stream's lambda transformations might no longer be triggered because the stream is evaluated / consumed on toString(), no longer in the real code. See:
https://youtrack.jetbrains.com/issue/IDEA-160867

@tcn
Copy link

tcn commented Sep 8, 2016

Streams are aimed to large(r) data sets (i.e. toString() is pointless anyways) and on purpose composable and lazily evaluated. Consider debugging through this:

final Seq<Integer> cache1 = Seq.of(1, 2, 3);    // and a whole lot more
final Seq<Integer> cache2 = cache1.filter(whatever);    
final Optional<Integer> r = cache2.sum();   // *this* is expected to land on the heap

And the current toString() doesn't even comma-separate the values :)

@lukaseder
Copy link
Member Author

lukaseder commented Sep 8, 2016

@tcn: Personally, I don't buy the "large(r)" data set argument. Most people will use streams as glorified collections, i.e. stuff with 1000 elements in it, where the stream source is in memory already.

Anyway, I see your point :)

@tcn
Copy link

tcn commented Sep 8, 2016

That's why Seq.parallel() returns this, I suppose :)

@lukaseder
Copy link
Member Author

No, why? Seq.parallel() returns this, because it makes no sense to have a parallel sequential stream

@tcn
Copy link

tcn commented Sep 14, 2016

@lukaseder
Copy link
Member Author

Wow, that's impressive. But what do you mean by "I was right"? With what?

@tcn
Copy link

tcn commented Sep 14, 2016

Uhm, well, that "most" people will use Stream/Seq as "glorified collections"; now that IntelliJ has this particular feature.

@lukaseder
Copy link
Member Author

Aha, I thought it was referring to the parallel() comment. Yes indeed, that's the assumption here. In fact, that's the whole reason for being of this library. People wanted cooler collections (as in Scala). Not infinite parallel Streams. Only Brian Goetz wanted that, and 1-2 of his peers ;) (Scala has those features too, but hardly anyone uses them)

@tcn
Copy link

tcn commented Sep 14, 2016

Hardly anyone uses DB cursors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants