summaryrefslogtreecommitdiff
path: root/Alpha.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Alpha.hs')
-rw-r--r--Alpha.hs26
1 files changed, 24 insertions, 2 deletions
diff --git a/Alpha.hs b/Alpha.hs
index 5d53f71..5ced72d 100644
--- a/Alpha.hs
+++ b/Alpha.hs
@@ -22,6 +22,10 @@ module Alpha
module X,
String,
+ -- * Composing
+ compose,
+ (.>),
+
-- * Applying
(<|),
(|>),
@@ -64,6 +68,22 @@ import Protolude as X hiding (($), (&))
say :: Text -> IO ()
say = putText
+-- | Composition
+compose :: (a -> b) -> (b -> c) -> (a -> c)
+compose f g x = g (f x)
+
+-- | Right-composition operator
+infixl 9 .>
+
+(.>) :: (a -> b) -> (b -> c) -> (a -> c)
+f .> g = compose f g
+
+-- | Left-composition operator
+infixr 9 <.
+
+(<.) :: (b -> c) -> (a -> b) -> (a -> c)
+g <. f = compose f g
+
-- | Alias for map, fmap, <$>
(</) :: Functor f => (a -> b) -> f a -> f b
f </ g = fmap f g
@@ -76,13 +96,15 @@ f </ g = fmap f g
-- | Normal function application. Do the right side, then pass the
-- return value to the function on the left side.
+infixr 0 <|
+
(<|) :: (a -> b) -> a -> b
f <| g = f g
-infixr 0 <|
-
-- | Reverse function application. Do the left side, then pass the
-- return value to the function on the right side.
+infixl 0 |>
+
(|>) :: a -> (a -> b) -> b
f |> g = g f