packages feed

polysemy-kvstore 0.1.0.0 → 0.1.1.0

raw patch · 3 files changed

+48/−3 lines, 3 files

Files

ChangeLog.md view
@@ -1,4 +1,8 @@-# Changelog for polysemy-methodology+# Changelog for polysemy-kvstore++## v0.1.1.0++* Add `runKVStoreAsKVStore` and `runKVStoreAsKVStoreSem`.  ## v0.1.0.0 
polysemy-kvstore.cabal view
@@ -5,8 +5,9 @@ -- see: https://github.com/sol/hpack  name:           polysemy-kvstore-version:        0.1.0.0-synopsis:       KVStore effect for polysemy+version:        0.1.1.0+synopsis:       KVStore effect for polysemy.+description:    KVStore effect for polysemy. category:       Polysemy author:         Daniel Firth maintainer:     dan.firth@homotopic.tech
src/Polysemy/KVStore.hs view
@@ -112,3 +112,43 @@   Sem r (M.Map k v, a) runKVStorePure m = runState m . runKVStoreAsState {-# INLINE runKVStorePure #-}++-- | Run a `KVStore` in terms of another `KVStore` by way of pure key and value+-- 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 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)+{-# 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 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'+{-# INLINE runKVStoreAsKVStoreSem #-}