antelude-0.1.0: src/Antelude/Function.hs
{- |
Module : Antelude.Function
Description : Contains some functional functions and symbols.
Maintainer : dneavesdev@pm.me
I realized after-the-fact that the arrows (which I was taking inspiration from Elm) is essentially part of what the 'flow' package does.
-}
module Antelude.Function
( constant
, identity
-- | Reexport from 'Data.Function'
, Prelude.flip
-- | Reexport from 'Prelude'
, Prelude.asTypeOf
-- | Reexport from 'Prelude'
, Prelude.seq
-- operators
, (.>)
, (<.)
, (<|)
, (|>)
) where
import safe qualified Prelude
-- | Re-return the first argument. Can be surprisingly useful.
identity :: a -> a
identity = Prelude.id
-- | Always return the first argument.
constant :: a -> b -> a
constant = Prelude.const
infixr 0 <|
-- | Equivalent to '($)' from 'Data.Function', but like Elm. Can be slightly clearer for unfamiliar developers.
(<|) :: (a -> b) -> a -> b
a <| b = a b
infixl 0 |>
-- | Equivalent to '(&)' from 'Data.Function', but like Elm. Can be slightly clearer for unfamiliar developers.
(|>) :: a -> (a -> b) -> b
a |> b = b a
infixl 9 <.
{- |
Equivalent to '(.)' from 'Data.Function', but in an arrowhead format.
Since '(<<)' would be confused with 'flip (>>)', '(<.)' was decided as it's `(.)` but with a direction.
-}
(<.) :: (b -> c) -> (a -> b) -> a -> c
a <. b = \x -> a <| b x
infixr 9 .>
{- |
Equivalent to 'flip (.)', but in an arrowhead format.
Since '(>>)' is already a typeclass-locked Haskell symbol for `Monad`, '(.>)' was decided as was decided as it's `(.)` but with a direction.
-}
(.>) :: (a -> b) -> (b -> c) -> a -> c
a .> b = \x -> b <| a x