My question is very similar to this one: Java 8 Streams: multiple filters vs. complex condition
Anyway this is not a duplicate, as internals of map and filter are very different. While filters reduce the number of elements over time, a different rationale is needed to decide which approach is best.
Still the question is identical: Which of the following two approaches is more efficient? Or is it actually the same, so I can decide by readability?
Approach 1:
Collection<Bar> in = ...;
Collection<Baz> out = in.stream().map(FooUtil::fromBar).map(BazUtil::fromFoo).collect(Collectors.toSet());
Approach 2:
Collection<Bar> in = ...;
Collection<Baz> out = in.stream().map(bar -> BazUtil.fromFoo(FooUtil.fromBar(bar))).collect(Collectors.toSet());
Edit: This is just an example with two steps. In my real use case I have a few more steps.
Edit 2: As discussed in the comments, there is basically no difference. Thus I go with the better readable option. If anybody stumbles upon this question, please read on in the linked question, as the same answer can be applied. Thus I'm now going to close my question as duplicate.