Skip to content

Instantly share code, notes, and snippets.

@itang
Created August 31, 2015 09:33
Show Gist options
  • Save itang/5c18111826fe1dc25f9f to your computer and use it in GitHub Desktop.
Save itang/5c18111826fe1dc25f9f to your computer and use it in GitHub Desktop.
tap when
defmodule A do
def tap_when(target, c, f) do
if c do
IO.puts "yes"
f.(target)
else
IO.puts "no"
target
end
end
end
"hello" |> A.tap_when true, &(&1 <> ", itang") |> IO.puts
@itang
Copy link
Author

itang commented Aug 31, 2015

output:
yes
hello, itang

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment