vavr-io / vavr

vʌvr (formerly called Javaslang) is a non-commercial, non-profit object-functional library that runs with Java 8+. It aims to reduce the lines of code and increase code quality.
https://vavr.io
Other
5.68k stars 631 forks source link

Peek() or tap() for tuples #2723

Open zatziky opened 2 years ago

zatziky commented 2 years ago

Tuples are missing a method that would return nothing, void. The method signature would be void tap(Closure /*will all tuple elements as input arg*/).

The use case is when you need to e.g. just to log elements, send something to backend, etc. Yes, the side-effects. :-)

A similar case is reported for collections: https://github.com/vavr-io/vavr/issues/2676

Can you please consider it so that we don't have to workaround it?

Workaround

Tuple.of(a, b).apply((in1, in2) -> {
   // some side-effects

  return "ignored"
})