1 min read

Ruby's tap and then

The tap and then methods are awesome ways to build functional pipelines, here's the simple difference between them
Ruby's tap and then
Photo by Anandan Anandan / Unsplash

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"