Ruby's tap and then
The tap and then methods are awesome ways to build functional pipelines, here's the simple difference between them
The tap
and then
methods are awesome ways to build functional pipelines, here's the simple difference between them.
The then
method takes the value from the previous statement and returns the result from its block.
The tap
method takes the values from the previous statement and returns the original value after its block.
Trivial examples:
'foo'.then { 'bar' }
#=> "bar"
'foo'.tap { 'bar' }
#=> "foo"
Member discussion