Closed tlinkowski closed 7 years ago
Thanks a lot for your PR!
does not have the exact semantics you expected
Maybe I didn't write it down this way, but the example is exactly what I would expect.
Thrown inside action.apply(T) - these are caught both upstream and downstream
Could you give an example for this?
Well, in #299 you wrote:
Seq.seq(source)
.filter(op1)
.filter(op2)
.peekThrowable(e -> ... /* only exceptions from op1 and op2 */)
.filter(op3)
.peekThrowable(e -> ... /* exceptions from op1, op2, or op3 */)
.collect(collector);
but we really have:
Seq.seq(source)
.filter(op1)
.filter(op2)
.peekThrowable(e -> ... /* all exceptions from op1 and op2 + most exceptions from op3 */)
.filter(op3)
.peekThrowable(e -> ... /* all exceptions from op1, op2, or op3 */)
.collect(collector);
for example:
Seq.of(1, 2, 3)
.filter(i -> i > 1)
.filter(i -> i <= 3)
.peekThrowable(System.out::println) // will print RuntimeException
.filter(i -> {
if (i == 3)
throw new RuntimeException();
return i < 3;
})
.toList();
Oh, interesting, thanks for clarifying. Then I don't agree with the status quo. Will revert. That's very surprising and doesn't work like peek()
...
See #91 and #299.
@lukaseder, you should be aware that the implementation I provided here (which is the same as proposed in #299) does not have the exact semantics you expected. Namely, the following test passes:
which means that
peekThrowable
works not only upstream but also downstream. The reason for this is (as far as I understand) that theaction
passed to the top-most (source)Spliterator.tryAdvance(Consumer<T> action)
represents (in a way) all the cumulated operations (up to the terminal operation).However, calling
peekThrowable
more up or down the stream can make a difference because we can catch two types ofThrowable
s:action.apply(T)
- these are caught both upstream and downstreamSpliterator.tryAdvance()
- these are caught only upstream