I want to do something like this:
servicesList.parallelStream()
.map(service-> pluginService.fetchSentinelFileAsString(projectModel, branch))
.filter(Optional::isPresent)
.map(Optional::get)
.map(model -> service.fetch(model));
Note that the service
parameter in the first lambda is reused in the foreach
lambda. This isn't legal but perhaps there's a way to do it.
Let me describe what that code is doing in case it helps:
- I have a list of references to services
- I want to use the service to get an
Optional
- If the
Optional
ispresent
I want to use the service again to process the content of theOptional
Put another way, I want to sorta reuse a value that was mapped in a previous stream item.
I really think of this as being one stream, but obviously each stream operation passes exactly ONE item to the next stage of the pipeline and this exceeds that limitations.