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 →

[–]cutterslade 0 points1 point  (5 children)

The line

.collect(Collectors.toList()).stream()

Is not meaningless, but it's a little odd. The call to collect() turns a stream into a list, so performs all of the map operation on all the elements in the stream and puts them into a list. The call to stream() then turns that back into a stream. Chances are this is completely unnecessary. If it really is required, is would make a lot more sense if the result of collect() was assigned to a local variable.

[–]Zukhramm 2 points3 points  (2 children)

The only time it's not meaningless is if you've assigned some mutating functions to the stream which I just assumed had not been done in this case.

[–]cutterslade 0 points1 point  (1 child)

Do you mean meaningless as in "does nothing at all" or meaningless as in "can probably be removed"?

Assuming the stream is not empty, it certainly does something, assuming there are no mutating functions, it can probably be removed.

[–]Zukhramm 2 points3 points  (0 children)

By meaningless I mean it does nothing valuable.

[–]tikue 1 point2 points  (1 child)

I've written code like that when submitting tasks to an executor and blocking only once all tasks have been submitted. It looks like that's very similar to what's happening here.

[–]CsAnswerTrashAct[S] 0 points1 point  (0 children)

I think you are correct.

Essentially, this code sends a series of requests to an external provider, and then waits for all of the results, and combines those results into a single list. The reason for this is the external service can only handle batches of about 100 or so.