co-log-core-0.3.2.5: Composable Contravariant Comonadic Logging Library

Copyright | (c) 2018-2020 Kowainik 2021-2025 Co-Log
License | MPL-2.0
Maintainer | Co-Log <xrom.xkov@gmail.com>
Stability | Stable
Portability | Portable
Safe Haskell | None
Language | Haskell2010

Colog.Core.Class

Contents

- Lens

Description

Provides type class for values that has access to `LogAction`.

Synopsis

- class HasLog env msg (m :: Type -> Type) where
  - getLogAction :: env -> LogAction m msg
  - setLogAction :: LogAction m msg -> env -> env
  - overLogAction :: (LogAction m msg -> LogAction m msg) -> env -> env
  - logActionL :: Lens' env (LogAction m msg)
- type Lens' s a = forall (f :: Type -> Type). Functor f => (a -> f a) -> s -> f s

# Documentation

class HasLog env msg (m :: Type -> Type) where Source #

This types class contains simple pair of getter-setter and related functions. It also provides the useful lens `logActionL` with the default implementation using type class methods. The default one could be easily overritten under your instances.

Every instance of the this typeclass should satisfy the following laws:

1. Set-Get: ``getLogAction` (`setLogAction` l env) ≡ l`
2. Get-Set: ``setLogAction` (`getLogAction` env) env ≡ env`
3. Set-Set: ``setLogAction` l2 (`setLogAction` l1 env) ≡ `setLogAction` l2 env`
4. Set-Over: ``overLogAction` f env ≡ `setLogAction` (f $ `getLogAction` env) env`

Minimal complete definition

logActionL | getLogAction, (setLogAction | overLogAction)

Methods

getLogAction :: env -> LogAction m msg Source #

Extracts `LogAction` from the environment.

setLogAction :: LogAction m msg -> env -> env Source #

Sets `LogAction` to the given one inside the environment.

overLogAction :: (LogAction m msg -> LogAction m msg) -> env -> env Source #

Applies function to the `LogAction` inside the environment.

logActionL :: Lens' env (LogAction m msg) Source #

Lens for `LogAction` inside the environment.

#### Instances

Instances details

HasLog (LogAction m msg) msg m Source # |
Instance details Defined in Colog.Core.Class Methods getLogAction :: LogAction m msg -> LogAction m msg Source # setLogAction :: LogAction m msg -> LogAction m msg -> LogAction m msg Source # overLogAction :: (LogAction m msg -> LogAction m msg) -> LogAction m msg -> LogAction m msg Source # logActionL :: Lens' (LogAction m msg) (LogAction m msg) Source #

# Lens

To keep `co-log-core` a lightweight library it was decided to introduce local `Lens'` type alias as it doesn't harm.

type Lens' s a = forall (f :: Type -> Type). Functor f => (a -> f a) -> s -> f s Source #

The monomorphic lenses which don't change the type of the container (or of the value inside).