{-# 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 = Const (LogAction m msg) env -> LogAction m msg
forall {k} a (b :: k). Const a b -> a
getConst (Const (LogAction m msg) env -> LogAction m msg)
-> (env -> Const (LogAction m msg) env) -> env -> LogAction m msg
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (LogAction m msg -> Const (LogAction m msg) (LogAction m msg))
-> env -> Const (LogAction m msg) env
forall env msg (m :: * -> *).
HasLog env msg m =>
Lens' env (LogAction m msg)
Lens' env (LogAction m msg)
logActionL LogAction m msg -> Const (LogAction m msg) (LogAction m msg)
forall {k} a (b :: k). a -> Const a b
Const
{-# INLINE getLogAction #-}
setLogAction :: LogAction m msg -> env -> env
setLogAction = (LogAction m msg -> LogAction m msg) -> env -> env
forall env msg (m :: * -> *).
HasLog env msg m =>
(LogAction m msg -> LogAction m msg) -> env -> env
overLogAction ((LogAction m msg -> LogAction m msg) -> env -> env)
-> (LogAction m msg -> LogAction m msg -> LogAction m msg)
-> LogAction m msg
-> env
-> env
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LogAction m msg -> LogAction m msg -> LogAction m msg
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 = LogAction m msg -> env -> env
forall env msg (m :: * -> *).
HasLog env msg m =>
LogAction m msg -> env -> env
setLogAction (LogAction m msg -> LogAction m msg
f (LogAction m msg -> LogAction m msg)
-> LogAction m msg -> LogAction m msg
forall a b. (a -> b) -> a -> b
$ env -> LogAction m msg
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 = (env -> LogAction m msg)
-> (env -> LogAction m msg -> env) -> Lens' env (LogAction m msg)
forall s a. (s -> a) -> (s -> a -> s) -> Lens' s a
lens env -> LogAction m msg
forall env msg (m :: * -> *).
HasLog env msg m =>
env -> LogAction m msg
getLogAction ((LogAction m msg -> env -> env) -> env -> LogAction m msg -> env
forall a b c. (a -> b -> c) -> b -> a -> c
flip LogAction m msg -> env -> env
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 = LogAction m msg -> LogAction m msg
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 = LogAction m msg -> LogAction m msg -> LogAction m msg
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 = (LogAction m msg -> LogAction m msg)
-> LogAction m msg -> LogAction m msg
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 LogAction m msg -> f (LogAction m msg) -> f (LogAction m msg)
forall a b. a -> f b -> f a
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 (a -> s) -> f a -> f s
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f a
f (s -> a
getter s
s)
{-# INLINE lens #-}