From 71940d9c84a317cf1ff007a64c34c929269f4ba3 Mon Sep 17 00:00:00 2001 From: Andrzej Rybczak Date: Mon, 29 Jun 2026 18:49:44 +0200 Subject: [PATCH 1/2] Add mapConsumer --- consumers/CHANGELOG.md | 3 +++ consumers/consumers.cabal | 2 +- .../src/Database/PostgreSQL/Consumers/Config.hs | 13 +++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/consumers/CHANGELOG.md b/consumers/CHANGELOG.md index 487016b..2e80176 100644 --- a/consumers/CHANGELOG.md +++ b/consumers/CHANGELOG.md @@ -1,3 +1,6 @@ +# consumers-2.3.5.0 (2026-??-??) +* Add `mapConsumer` to ` Database.PostgreSQL.Consumers.Config`. + # consumers-2.3.4.0 (2025-11-27) * Compatibility with `hpqtypes` >= 1.13.0.0. diff --git a/consumers/consumers.cabal b/consumers/consumers.cabal index 5754092..b9a3e96 100644 --- a/consumers/consumers.cabal +++ b/consumers/consumers.cabal @@ -1,6 +1,6 @@ cabal-version: 3.0 name: consumers -version: 2.3.4.0 +version: 2.3.5.0 synopsis: Concurrent PostgreSQL data consumers description: Library for setting up concurrent consumers of data diff --git a/consumers/src/Database/PostgreSQL/Consumers/Config.hs b/consumers/src/Database/PostgreSQL/Consumers/Config.hs index fde9636..3fb60e5 100644 --- a/consumers/src/Database/PostgreSQL/Consumers/Config.hs +++ b/consumers/src/Database/PostgreSQL/Consumers/Config.hs @@ -2,6 +2,7 @@ module Database.PostgreSQL.Consumers.Config ( Action (..) , Result (..) , ConsumerConfig (..) + , mapConsumer ) where import Control.Exception (SomeException) @@ -117,3 +118,15 @@ data ConsumerConfig m idx job = forall row. FromRow row => ConsumerConfig , ccJobLogData :: !(job -> [A.Pair]) -- ^ Data to attach to each log message while processing a job. } + +-- | Map the consumer to operate in a different monad. +mapConsumer + :: (forall r. m r -> n r) + -> ConsumerConfig m idx job + -> ConsumerConfig n idx job +mapConsumer f ConsumerConfig {..} = + ConsumerConfig + { ccProcessJob = f . ccProcessJob + , ccOnException = \ex -> f . ccOnException ex + , .. + } From a3455c164fc9ae2f2d3658fabd733876081c9fc5 Mon Sep 17 00:00:00 2001 From: Andrzej Rybczak Date: Wed, 8 Jul 2026 20:23:18 +0200 Subject: [PATCH 2/2] Rename to hoistConsumer --- consumers/CHANGELOG.md | 2 +- consumers/src/Database/PostgreSQL/Consumers/Config.hs | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/consumers/CHANGELOG.md b/consumers/CHANGELOG.md index 2e80176..0de28c3 100644 --- a/consumers/CHANGELOG.md +++ b/consumers/CHANGELOG.md @@ -1,5 +1,5 @@ # consumers-2.3.5.0 (2026-??-??) -* Add `mapConsumer` to ` Database.PostgreSQL.Consumers.Config`. +* Add `hoistConsumer` to `Database.PostgreSQL.Consumers.Config`. # consumers-2.3.4.0 (2025-11-27) * Compatibility with `hpqtypes` >= 1.13.0.0. diff --git a/consumers/src/Database/PostgreSQL/Consumers/Config.hs b/consumers/src/Database/PostgreSQL/Consumers/Config.hs index 3fb60e5..b759594 100644 --- a/consumers/src/Database/PostgreSQL/Consumers/Config.hs +++ b/consumers/src/Database/PostgreSQL/Consumers/Config.hs @@ -2,7 +2,7 @@ module Database.PostgreSQL.Consumers.Config ( Action (..) , Result (..) , ConsumerConfig (..) - , mapConsumer + , hoistConsumer ) where import Control.Exception (SomeException) @@ -119,12 +119,12 @@ data ConsumerConfig m idx job = forall row. FromRow row => ConsumerConfig -- ^ Data to attach to each log message while processing a job. } --- | Map the consumer to operate in a different monad. -mapConsumer +-- | Change the monad the consumer lives in. +hoistConsumer :: (forall r. m r -> n r) -> ConsumerConfig m idx job -> ConsumerConfig n idx job -mapConsumer f ConsumerConfig {..} = +hoistConsumer f ConsumerConfig {..} = ConsumerConfig { ccProcessJob = f . ccProcessJob , ccOnException = \ex -> f . ccOnException ex