{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE Rank2Types #-}
module Colog.Core.Class
( HasLog (..)
, Lens'
) where
import Colog.Core.Action (LogAction)
import Data.Functor.Const (Const (..))
class HasLog env msg m where
{-# MINIMAL logActionL | (getLogAction , (setLogAction | overLogAction)) #-}
getLogAction :: env -> LogAction m msg
getLogAction = forall {k} a (b :: k). Const a b -> a
getConst forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall env msg (m :: * -> *).
HasLog env msg m =>
Lens' env (LogAction m msg)
logActionL forall {k} a (b :: k). a -> Const a b
Const
{-# INLINE getLogAction #-}
setLogAction :: LogAction m msg -> env -> env
setLogAction = forall env msg (m :: * -> *).
HasLog env msg m =>
(LogAction m msg -> LogAction m msg) -> env -> env
overLogAction forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. a -> b -> a
const
{-# INLINE setLogAction #-}
overLogAction :: (LogAction m msg -> LogAction m msg) -> env -> env
overLogAction LogAction m msg -> LogAction m msg
f env
env = forall env msg (m :: * -> *).
HasLog env msg m =>
LogAction m msg -> env -> env
setLogAction (LogAction m msg -> LogAction m msg
f forall a b. (a -> b) -> a -> b
$ forall env msg (m :: * -> *).
HasLog env msg m =>
env -> LogAction m msg
getLogAction env
env) env
env
{-# INLINE overLogAction #-}
logActionL :: Lens' env (LogAction m msg)
logActionL = forall s a. (s -> a) -> (s -> a -> s) -> Lens' s a
lens forall env msg (m :: * -> *).
HasLog env msg m =>
env -> LogAction m msg
getLogAction (forall a b c. (a -> b -> c) -> b -> a -> c
flip forall env msg (m :: * -> *).
HasLog env msg m =>
LogAction m msg -> env -> env
setLogAction)
{-# INLINE logActionL #-}
instance HasLog (LogAction m msg) msg m where
getLogAction :: LogAction m msg -> LogAction m msg
getLogAction :: LogAction m msg -> LogAction m msg
getLogAction = forall a. a -> a
id
{-# INLINE getLogAction #-}
setLogAction :: LogAction m msg -> LogAction m msg -> LogAction m msg
setLogAction :: LogAction m msg -> LogAction m msg -> LogAction m msg
setLogAction = forall a b. a -> b -> a
const
{-# INLINE setLogAction #-}
overLogAction
:: (LogAction m msg -> LogAction m msg)
-> LogAction m msg
-> LogAction m msg
overLogAction :: (LogAction m msg -> LogAction m msg)
-> LogAction m msg -> LogAction m msg
overLogAction = forall a. a -> a
id
{-# INLINE overLogAction #-}
logActionL :: Lens' (LogAction m msg) (LogAction m msg)
logActionL :: Lens' (LogAction m msg) (LogAction m msg)
logActionL = \LogAction m msg -> f (LogAction m msg)
f LogAction m msg
s -> LogAction m msg
s forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ LogAction m msg -> f (LogAction m msg)
f LogAction m msg
s
{-# INLINE logActionL #-}
type Lens' s a = forall f. Functor f => (a -> f a) -> s -> f s
lens :: (s -> a) -> (s -> a -> s) -> Lens' s a
lens :: forall s a. (s -> a) -> (s -> a -> s) -> Lens' s a
lens s -> a
getter s -> a -> s
setter = \a -> f a
f s
s -> s -> a -> s
setter s
s forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f a
f (s -> a
getter s
s)
{-# INLINE lens #-}