3 ms·
> evaluation begins only when a terminal operation is invoked. In this example, line (1) creates a stream, but does not evaluate it, line (2) sets up an interme
by another-dave 3y ago
> evaluation begins only when a terminal operation is invoked. In this example, line (1) creates a stream, but does not evaluate it, line (2) sets up an intermediate filter operation but still does not evaluate the stream, and finally the terminal collect operation on line (3) evaluates the entire stream pipeline.
It's quite clear, reading beyond just the code, that the original author is talking about _computational_ efficiency.
It feels like you missed the point — that streams are only evaluated lazily as needed — in order to poke fun at the (toy) example.
The Java code can (and in a real-world application would), be made more consise (e.g. via static imports) but the author is deliberately being more verbose to be more explicit in what's going on.
- mrkeen 3y ago> It feels like you missed the point — that streams are only evaluated lazily as needed — in order to poke fun at the (toy) example. GP may be closer to the point than you realise, even if unintentionally so. I mentioned Streams failing to be lazy in another comment, and predictably got down-votes rather than corrections. So anyway... https://bugs.java.com/bugdatabase/view_bug?bug_id=8079264 https://bugs.java.com/bugdatabase/view_bug?bug_id=8079264 Submitted: 2015-05-01 https://bugs.java.com/bugdatabase/view_bug?bug_id=8149614 https://bugs.java.com/bugdatabase/view_bug?bug_id=8149614 Submitted: 2016-02-10 https://bugs.java.com/bugdatabase/view_bug?bug_id=8155217 https://bugs.java.com/bugdatabase/view_bug?bug_id=8155217 Submitted: 2016-04-25 https://bugs.java.com/bugdatabase/view_bug?bug_id=8189234 https://bugs.java.com/bugdatabase/view_bug?bug_id=8189234 Submitted: 2017-10-11 https://bugs.java.com/bugdatabase/view_bug?bug_id=8196106 https://bugs.java.com/bugdatabase/view_bug?bug_id=8196106 Submitted: 2018-01-24 https://bugs.java.com/bugdatabase/view_bug?bug_id=8229983 https://bugs.java.com/bugdatabase/view_bug?bug_id=8229983 Submitted: 2019-08-21 https://bugs.java.com/bugdatabase/view_bug?bug_id=8267758 https://bugs.java.com/bugdatabase/view_bug?bug_id=8267758 Submitted: 2021-05-25 I wonder if 2024 will be the year of the lazy Stream.
- another-dave 3y agoI think the point that you are making — that even if Streams are meant to be efficient on paper, but reality is different because of bugs in implementation — is an interesting one that moves on the discussion! Surprised to hear you were downvoted for it. Personally, I don't think that's what the other comment was getting at though, as they were commenting on efficiency regards to syntax.
- lbalazscs 3y agoI hope that 2024 will be the year when people stop pointing to duplicate or fixed bugs...
- mrkeen 3y agoFirstly, I put multiple bug reports there to show that 'real programmers' are running into real bugs in the wild. This is necessary because otherwise when I point out bugs, I'm dismissed as a "PL fan" whose ivory tower views don't line up with the mainstream. See elsewhere in the comments. Secondly, if I click into my first link (2015), it says resolved 2015. And by 'resolved' it means 'duplicate but not fixed'. Because when I clicked into its duplicate, it wasn't 'resolved' until 2018. What did they resolve if tickets are still being filed in 2019 and 2021?
- lbalazscs 3y agoMy understanding is that Stream internals are a very complex piece of software that can have multiple different bugs. By the way, I agree with you that eager versions of the Stream methods should also be available directly on the collections.
- Calzifer 3y agoThe last three are open, open and won't fix. Not so promising for the flatMap method.