What is the idiomatic way of printing (or doing whatever thing I need to do) and returning value in Scala? For example,
Seq(1,2,3)
.map(_ * 2)
.xxx(println) // Here I want to print the intermediate sequence
.foldLeft(0)(_ + _)
One way I can think of is using implicit but I don't really like to monkey patch standard library myself.
Note
In Ruby we can use Object#tap
[1,2,3]
.map { |i| i * 2 }
.tap { |i| puts i }
.reduce(0) { |x, i| x += i }