tap and then
  •  1 min read

tap/2

tap(value, fn x) -> value

Applies the value into the function and returns the original value. I rarely use this, but can be helpful when printf debugging.

tap("Gandalf", fn name -> "Hello, #{name}" end)

# Gandalf

then/2

then(value, fn x) -> fn result

Applies the value into the function and return the result of the function. Mostly used inside of pipelines.

"  Gandalf  "
|> String.trim()
|> then(fn name -> "Hello, #{name}" end)

# Hello, Gandalf