Last active
December 19, 2015 17:08
-
-
Save leroux/5988483 to your computer and use it in GitHub Desktop.
Haskell Chain
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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