|
|
|
|
|
by majewsky
2712 days ago
|
|
It also reminds me of Ruby's .tap { |x| puts x }
For those of you who don't know Ruby, its map/filter/reduce functions chain like this: values.map { |x| x + 2 }.select { |x| x > 3 }
So when you want to look at an intermediate result, there's the .tap() method that runs a lambda with that intermediate result, then passes it on to the next step in the chain. [0, 1, 2, 3].map { |x| x + 2 }.tap { |x| puts x }.select { |x| x > 3 }
This returns [4, 5] after printing [2, 3, 4, 5]. ("puts" is Ruby's println.) |
|