Skip to content

Instantly share code, notes, and snippets.

@cohei
Last active June 25, 2020 16:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cohei/a47ed793f5143c165e8e to your computer and use it in GitHub Desktop.
Save cohei/a47ed793f5143c165e8e to your computer and use it in GitHub Desktop.
Ruby's tap in Haskell
import Data.Functor
tap :: Functor f => a -> (a -> f b) -> f a
x `tap` action = x <$ action x
-- Only standard output
-- >>> print 1
-- 1
-- Standard output and return value
-- >>> 1 `tap` print
-- 1
-- 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment