I understand that Java stream object doesn't allow forked stream
. But it's also reasonable to imagine one would perform multiple actions to the same stream. Say I want to map a List of objects but also sum up a measurement across all objects. I'd like to know if it's possible to do so without dump data into a List.
Stream<Thing> thingStream = ...;
int accumulation = thingStream.mapToInt(Thing::measure).sum();
List<Another> results = thingStream.map(t -> toAnother(t)).collect(toList());
I know it's possible to use Stream#peek
but it sounds hacky.