polysemy-methodology-co-log (empty) → 0.1.0.0
raw patch · 5 files changed
+171/−0 lines, 5 filesdep +basedep +co-log-polysemydep +polysemy
Dependencies added: base, co-log-polysemy, polysemy, polysemy-methodology, polysemy-plugin
Files
- ChangeLog.md +5/−0
- LICENSE +30/−0
- README.md +3/−0
- polysemy-methodology-co-log.cabal +39/−0
- src/Polysemy/Methodology/Colog.hs +94/−0
+ ChangeLog.md view
@@ -0,0 +1,5 @@+# Changelog for polysemy-methodology-co-log++## v0.1.0.0++Add `logMethodologyStart`, `logMethodologyEnd` and `logMethodologyAround`.
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright Daniel Firth (c) 2020++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++ * Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.++ * Redistributions in binary form must reproduce the above+ copyright notice, this list of conditions and the following+ disclaimer in the documentation and/or other materials provided+ with the distribution.++ * Neither the name of Author name here nor the names of other+ contributors may be used to endorse or promote products derived+ from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ README.md view
@@ -0,0 +1,3 @@+# polysemy-methodology-co-log++Logging for [polysemy-methodology](https://hackage.haskell.org/package/polysemy-methodology).
+ polysemy-methodology-co-log.cabal view
@@ -0,0 +1,39 @@+cabal-version: 1.12++-- This file has been generated from package.yaml by hpack version 0.34.4.+--+-- see: https://github.com/sol/hpack++name: polysemy-methodology-co-log+version: 0.1.0.0+synopsis: Logging functions for polysemy-methodology.+category: Polysemy+author: Daniel Firth+maintainer: dan.firth@homotopic.tech+copyright: 2020 Daniel Firth+license: MIT+license-file: LICENSE+build-type: Simple+extra-source-files:+ README.md+ ChangeLog.md++source-repository head+ type: git+ location: https://gitlab.com/homotopic-tech/polysemy-methodology-co-log++library+ exposed-modules:+ Polysemy.Methodology.Colog+ other-modules:+ Paths_polysemy_methodology_co_log+ hs-source-dirs:+ src+ ghc-options: -Wall -Wcompat -Wincomplete-record-updates -Wincomplete-uni-patterns -Wredundant-constraints+ build-depends:+ base >=4.7 && <4.16+ , co-log-polysemy+ , polysemy >=1.3.0.0 && <1.7+ , polysemy-methodology >=0.1 && <0.3+ , polysemy-plugin >=0.3 && <0.5+ default-language: Haskell2010
+ src/Polysemy/Methodology/Colog.hs view
@@ -0,0 +1,94 @@+{-# LANGUAGE AllowAmbiguousTypes #-}+{-# LANGUAGE BlockArguments #-}+{-# LANGUAGE DataKinds #-}+{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE GADTs #-}+{-# LANGUAGE LambdaCase #-}+{-# LANGUAGE PolyKinds #-}+{-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE TemplateHaskell #-}+{-# LANGUAGE TypeApplications #-}+{-# LANGUAGE TypeOperators #-}+{-# OPTIONS_GHC -fplugin=Polysemy.Plugin #-}++-- |+-- Module : Polysemy.Methodology+-- License : MIT+-- Stability : experimental+--+-- Domain modelling algebra for polysemy.+module Polysemy.Methodology.Colog+ ( -- * Logging+ logMethodologyStart,+ logMethodologyEnd,+ logMethodologyAround,+ )+where++import Colog.Polysemy as C+import Polysemy+import Polysemy.Methodology++-- | `Log` a type based on the input to a `Methodology`.+--+-- @since 0.1.0.0+logMethodologyStart ::+ forall b c p r a.+ Members+ '[ Methodology b c,+ Log p+ ]+ r =>+ -- | A function from the input type b to an event type p.+ (b -> p) ->+ Sem r a ->+ Sem r a+logMethodologyStart f = intercept \case+ Process b -> C.log (f b) >> process @b @c b+{-# INLINE logMethodologyStart #-}++-- | `Log` a type based on the output to a `Methodology`.+--+-- @since 0.1.0.0+logMethodologyEnd ::+ forall b c q r a.+ Members+ '[ Methodology b c,+ Log q+ ]+ r =>+ -- | A function from the input type c to an event type q.+ (c -> q) ->+ Sem r a ->+ Sem r a+logMethodologyEnd f = intercept \case+ Process b -> do+ c <- process @b @c b+ C.log $ f c+ return c+{-# INLINE logMethodologyEnd #-}++-- | `Log` both the start and the end of a `Methodology`.+--+-- @since 0.1.0.0+logMethodologyAround ::+ forall b c p q r a.+ Members+ '[ Methodology b c,+ Log p,+ Log q+ ]+ r =>+ -- | A function from the input type b to an event type p.+ (b -> p) ->+ -- | A function from the output type b to an event type q,+ (c -> q) ->+ Sem r a ->+ Sem r a+logMethodologyAround f g = intercept \case+ Process b -> do+ C.log $ f b+ c <- process @b @c b+ C.log $ g c+ return c+{-# INLINE logMethodologyAround #-}