Skip to content

Instantly share code, notes, and snippets.

@leroux
Last active December 19, 2015 17:08
Show Gist options
  • Save leroux/5988483 to your computer and use it in GitHub Desktop.
Save leroux/5988483 to your computer and use it in GitHub Desktop.
Haskell Chain
module Chain where
infixl 2 .>
infixr 1 .>>
{-| Chain operator.
Chain functions in a do-like (monadic bind)-like style.
`f .> g` will return a function that will apply f, then apply g.
It can be alternatively be defined as: `f .> g = g . f` which is just
`flip (.)`.
-}
(.>) :: (a -> b) -> (b -> c) -> a -> c
(.>) = flip (.)
{-| Pass to. (Reverse of applying.)
Convenience function to use with applying chained functions.
This enables the following:
`x .>> f .> g`
instead of
`(f .> g) x` or `g (f x)`.
-}
(.>>) :: a -> (a -> b) -> b
a .>> f = f a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment