On 25/09/2025 21:46, [email protected] wrote:


------------------------------------------------------------------------

    *From: *"Alan Bateman" <[email protected]>
    *To: *"Remi Forax" <[email protected]>, "loom-dev"
    <[email protected]>
    *Sent: *Thursday, September 25, 2025 3:50:16 PM
    *Subject: *Re: Remark on the StructuredTaskScope API of Java 25

    On 24/09/2025 16:37, Remi Forax wrote:

        :

           - allSuccessfulOrThrow() should return a Joiner<T, 
List<Subtask<T>>>, so the result is a List and not a stream.
             In terms of implementation, in result(), the code should be
               return Collections.unmodifiableList(subtasks);

    Can you say more on this? Right now, preferring a stream works
    well. For a Joiner returned by allSuccessfulOrThrow it makes it
    easy to use join().map(Subtask::get) or other mapping function.
Add .toList() to get a list.

A collection is more powerful than a Stream, you can always do more with a List than with a Stream
(like indexed access).

Yes, you can always call toList() on a stream, but you are asking to duplicate all the elements, here stream.toList() is semantically equivalent to a call to List.copyOf(), so it's slow if you have quite a lot of elements.

So yes, it might be convenient for some use cases to return a stream than to call .stream() on the returned List,
but you are trading convenience for performance.

I don't think this is right argument to change it to return List. However, another angle is that users might assume the stream is lazily populated and that results can be consumed before join completes. For this Joiner, join is meant to wait until all subtasks complete or any subtask fails. So while returning a Stream is much more flexible, it may indeed be better to return a List<T>.

-Alan

Reply via email to