Is there an idiomatic Ruby equivalent Object#tapfor Unix command pipelines?
Use case: in the pipeline I want to execute a command for my side effects, but implicitly return the input so as not to break the chain of the pipeline. For instance:
echo { 1, 2, 3 } |
tr ' ' '\n' |
sort |
tap 'xargs echo' |
uniq
I come from Ruby where I would do this:
[ 1, 2, 3 ].
sort.
tap { |x| puts x }.
uniq
source
share