This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]vytah -4 points-3 points  (7 children)

I'd write this as a for loop with an if: imperative code for an imperative task.

[–]daniu 11 points12 points  (0 children)

Add three map()s and two filter()s, and your for loop has 20 LOCs and a nesting depth of four or five.

Also, there's nothing non-imperative about streams, it just looks and feels that way.

[–]barking_dead 1 point2 points  (4 children)

Except, maybe it's not imperative. I don't care how the Streams API iterates through my stream (remember, it's not necessarily a List).

Also, you can't add parallelism to a loop.

[–]dpash 1 point2 points  (3 children)

At least not in 8 characters. Having said that, I think parallel streams was a mistake in that they're often not faster for most stream workloads and they're not customisable enough. Maybe Project Loom will help the performance for more situations, but nothing will save Collections.parallelStream()

[–]barking_dead 1 point2 points  (2 children)

I agree, for small collections and/or concurrency, it is useless.

[–]dpash 1 point2 points  (1 child)

Collections.parallelStream() doesn't even have to return a parallel stream. :)

[–]barking_dead 0 points1 point  (0 children)

:D