polysemy-kvstore 0.1.1.1 → 0.1.2.0
raw patch · 3 files changed
+32/−30 lines, 3 files
Files
- ChangeLog.md +1/−1
- polysemy-kvstore.cabal +1/−1
- src/Polysemy/KVStore.hs +30/−28
ChangeLog.md view
@@ -1,6 +1,6 @@ # Changelog for polysemy-kvstore -## v0.1.1.0+## v0.1.2.0 * Add `runKVStoreAsKVStore` and `runKVStoreAsKVStoreSem`.
polysemy-kvstore.cabal view
@@ -5,7 +5,7 @@ -- see: https://github.com/sol/hpack name: polysemy-kvstore-version: 0.1.1.1+version: 0.1.2.0 synopsis: KVStore effect for polysemy. description: KVStore effect for polysemy. category: Polysemy
src/Polysemy/KVStore.hs view
@@ -1,4 +1,5 @@ {-# LANGUAGE AllowAmbiguousTypes #-}+{-# LANGUAGE BlockArguments #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE ExplicitForAll #-} {-# LANGUAGE FlexibleContexts #-}@@ -26,9 +27,8 @@ -- * Interpretations runKVStoreAsState, runKVStorePure,- runKVStoreAsKVStore,- runKVStoreAsKVStoreSem+ runKVStoreAsKVStoreSem, ) where @@ -120,38 +120,40 @@ -- transformations. -- -- @since 0.1.1.0-runKVStoreAsKVStore :: forall k v k' v' r a.- (k -> k')- -- ^ A function to transform the key into the interpreted key.- -> (v -> v')- -- ^ A function to transform the value into the interpreted value.- -> (v' -> v )- -- ^ A function to transform the interpreted key back into the current value.- -> Sem (KVStore k v ': r) a- -> Sem (KVStore k' v' ': r) a+runKVStoreAsKVStore ::+ forall k v k' v' r a.+ -- | A function to transform the key into the interpreted key.+ (k -> k') ->+ -- | A function to transform the value into the interpreted value.+ (v -> v') ->+ -- | A function to transform the interpreted key back into the current value.+ (v' -> v) ->+ Sem (KVStore k v ': r) a ->+ Sem (KVStore k' v' ': r) a runKVStoreAsKVStore f g h = reinterpret \case-LookupKV k -> fmap h <$> lookupKV @k' @v' (f k)-UpdateKV k x -> updateKV @k' @v' (f k) (fmap g x)+ LookupKV k -> fmap h <$> lookupKV @k' @v' (f k)+ UpdateKV k x -> updateKV @k' @v' (f k) (fmap g x) {-# INLINE runKVStoreAsKVStore #-} -- | Run a `KVStore` in terms of another `KVStore` by way of transforming the -- keys and values with Sem functions. -- -- @since 0.1.1.0-runKVStoreAsKVStoreSem :: forall k v k' v' r a.- Members '[KVStore k' v'] r- => (k -> Sem r k')- -- ^ A function to transform the key into the interpreted key.- -> (v -> Sem r v')- -- ^ A function to transform the value into the interpreted value.- -> (v' -> Sem r v )- -- ^ A function to transform the interpreted value back into the current value.- -> Sem (KVStore k v ': r) a- -> Sem r a+runKVStoreAsKVStoreSem ::+ forall k v k' v' r a.+ Members '[KVStore k' v'] r =>+ -- | A function to transform the key into the interpreted key.+ (k -> Sem r k') ->+ -- | A function to transform the value into the interpreted value.+ (v -> Sem r v') ->+ -- | A function to transform the interpreted value back into the current value.+ (v' -> Sem r v) ->+ Sem (KVStore k v ': r) a ->+ Sem r a runKVStoreAsKVStoreSem f g h = interpret \case-LookupKV k -> f k >>= lookupKV @k' @v' >>= mapM h-UpdateKV k x -> do-z <- f k-z' <- mapM g x-updateKV @k' @v' z z'+ LookupKV k -> f k >>= lookupKV @k' @v' >>= mapM h+ UpdateKV k x -> do+ z <- f k+ z' <- mapM g x+ updateKV @k' @v' z z' {-# INLINE runKVStoreAsKVStoreSem #-}