{-# LANGUAGE DeriveAnyClass #-}

{- | We use `relude` as our prelude; any extra Prelude-like functionality is put
 here.
-}
module Emanote.Prelude where

import Control.Monad.Logger (MonadLogger, logDebugNS, logErrorNS, logInfoNS, logWarnNS)
import Relude

-- | Monadic version of `chain`
chainM :: Monad m => (b -> m (a -> a)) -> [b] -> m (a -> a)
chainM :: forall (m :: Type -> Type) b a.
Monad m =>
(b -> m (a -> a)) -> [b] -> m (a -> a)
chainM b -> m (a -> a)
f =
  forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. [a -> a] -> a -> a
chain forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: Type -> Type) (m :: Type -> Type) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM b -> m (a -> a)
f
  where
    -- Apply the list of actions in the given order to an initial argument.
    --
    -- chain [f1, f2, ...] a = ... (f2 (f1 x))
    chain :: [a -> a] -> a -> a
    chain :: forall a. [a -> a] -> a -> a
chain = forall a b c. (a -> b -> c) -> b -> a -> c
flip forall a b. (a -> b) -> a -> b
$ forall (f :: Type -> Type) a b.
Foldable f =>
(a -> b -> b) -> b -> f a -> b
flipfoldl' forall a b. (a -> b) -> a -> b
($)

-- | User-provided input is malformed.
newtype BadInput = BadInput Text
  deriving stock (Int -> BadInput -> ShowS
[BadInput] -> ShowS
BadInput -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BadInput] -> ShowS
$cshowList :: [BadInput] -> ShowS
show :: BadInput -> String
$cshow :: BadInput -> String
showsPrec :: Int -> BadInput -> ShowS
$cshowsPrec :: Int -> BadInput -> ShowS
Show)
  deriving anyclass (Show BadInput
Typeable @Type BadInput
SomeException -> Maybe BadInput
BadInput -> String
BadInput -> SomeException
forall e.
Typeable @Type e
-> Show e
-> (e -> SomeException)
-> (SomeException -> Maybe e)
-> (e -> String)
-> Exception e
displayException :: BadInput -> String
$cdisplayException :: BadInput -> String
fromException :: SomeException -> Maybe BadInput
$cfromException :: SomeException -> Maybe BadInput
toException :: BadInput -> SomeException
$ctoException :: BadInput -> SomeException
Exception)

-------------
-- Logging
--------------

log :: MonadLogger m => Text -> m ()
log :: forall (m :: Type -> Type). MonadLogger m => Text -> m ()
log = forall (m :: Type -> Type). MonadLogger m => Text -> Text -> m ()
logInfoNS Text
"emanote"

logD :: MonadLogger m => Text -> m ()
logD :: forall (m :: Type -> Type). MonadLogger m => Text -> m ()
logD = forall (m :: Type -> Type). MonadLogger m => Text -> Text -> m ()
logDebugNS Text
"emanote"

logE :: MonadLogger m => Text -> m ()
logE :: forall (m :: Type -> Type). MonadLogger m => Text -> m ()
logE = forall (m :: Type -> Type). MonadLogger m => Text -> Text -> m ()
logErrorNS Text
"emanote"

logW :: MonadLogger m => Text -> m ()
logW :: forall (m :: Type -> Type). MonadLogger m => Text -> m ()
logW = forall (m :: Type -> Type). MonadLogger m => Text -> Text -> m ()
logWarnNS Text
"emanote"