packages feed

dynamodb-simple 0.6.0.1 → 0.6.0.2

raw patch · 4 files changed

+106/−7 lines, 4 filesdep +mtldep −monad-supply

Dependencies added: mtl

Dependencies removed: monad-supply

Files

dynamodb-simple.cabal view
@@ -1,5 +1,5 @@ name:                dynamodb-simple-version:             0.6.0.1+version:             0.6.0.2 synopsis:            Typesafe library for working with DynamoDB database description:         Framework for accessing DynamoDB database. The majority of AWS API                      is available to the user in a convenient, simple and typesafe manner.@@ -26,14 +26,15 @@   other-modules:       Database.DynamoDB.Class, Database.DynamoDB.Migration,                        Database.DynamoDB.Internal, Database.DynamoDB.BatchRequest,                        Database.DynamoDB.QueryRequest, Database.DynamoDB.THLens,-                       Database.DynamoDB.THContains, Database.DynamoDB.THConvert+                       Database.DynamoDB.THContains, Database.DynamoDB.THConvert,+                       Control.Monad.Supply   build-depends:       base >=4.9 && <5, amazonka-dynamodb >= 1.6.0, generics-sop,                        unordered-containers, text, lens, double-conversion,-                       semigroups, bytestring >= 0.10.8.0, containers, monad-supply,+                       semigroups, bytestring >= 0.10.8.0, containers,                         template-haskell, transformers, exceptions,                        amazonka, monad-loops, conduit, hashable,                        amazonka-core, aeson, vector, scientific,-                       tagged, uuid-types+                       tagged, uuid-types, mtl                        -- hspec, safe-exceptions   hs-source-dirs:      src   default-language:    Haskell2010
+ src/Control/Monad/Supply.hs view
@@ -0,0 +1,96 @@+{-# LANGUAGE CPP                        #-}+{-# LANGUAGE FlexibleInstances          #-}+{-# LANGUAGE FunctionalDependencies     #-}+{-# LANGUAGE GeneralizedNewtypeDeriving #-}+{-# LANGUAGE UndecidableInstances       #-}+{-# LANGUAGE LambdaCase                 #-}++-- | Support for computations which consume values from a (possibly infinite)+-- supply. See <http://www.haskell.org/haskellwiki/New_monads/MonadSupply> for+-- details.++module Control.Monad.Supply+( MonadSupply (..)+, SupplyT+, Supply+, evalSupplyT+, evalSupply+, runSupplyT+, runSupply+, supplies+) where++import           Control.Monad.Except+import           Control.Monad.Identity+import           Control.Monad.Reader+import           Control.Monad.State+import           Control.Monad.Writer   hiding ((<>))+import           Data.Semigroup++class Monad m => MonadSupply s m | m -> s where+  supply :: m s+  peek :: m s+  exhausted :: m Bool++-- | Supply monad transformer.+newtype SupplyT s m a = SupplyT (StateT [s] m a)+  deriving (Functor, Applicative, Monad, MonadTrans, MonadIO, MonadFix)++-- | Supply monad.+newtype Supply s a = Supply (SupplyT s Identity a)+  deriving (Functor, Applicative, Monad, MonadSupply s, MonadFix)++instance Monad m => MonadSupply s (SupplyT s m) where+  supply = SupplyT $ do +     get >>= \case+       [] -> error "Supply drained."+       (x:xs) -> do+          put xs+          return x+  peek = SupplyT $ gets head+  exhausted = SupplyT $ gets null++-- Monad transformer instances+instance (MonadSupply s m) => MonadSupply s (ExceptT e m) where+  supply = lift supply+  peek = lift peek+  exhausted = lift exhausted++instance MonadSupply s m => MonadSupply s (StateT st m) where+  supply = lift supply+  peek = lift peek+  exhausted = lift exhausted++instance MonadSupply s m => MonadSupply s (ReaderT r m) where+  supply = lift supply+  peek = lift peek+  exhausted = lift exhausted++instance (Monoid w, MonadSupply s m) => MonadSupply s (WriterT w m) where+  supply = lift supply+  peek = lift peek+  exhausted = lift exhausted++instance Semigroup a => Semigroup (Supply s a) where+  m1 <> m2 = (<>) <$> m1 <*> m2++instance (Semigroup a, Monoid a) => Monoid (Supply s a) where+  mempty = return mempty+  m1 `mappend` m2 = m1 <> m2++-- | Get n supplies.+supplies :: MonadSupply s m => Int -> m [s]+supplies n = replicateM n supply++evalSupplyT :: Monad m => SupplyT s m a -> [s] -> m a+evalSupplyT (SupplyT s) = evalStateT s++evalSupply :: Supply s a -> [s] -> a+evalSupply (Supply s) = runIdentity . evalSupplyT s++runSupplyT :: Monad m => SupplyT s m a -> [s] -> m (a,[s])+runSupplyT (SupplyT s) = runStateT s++runSupply :: Supply s a -> [s] -> (a,[s])+runSupply (Supply s) = runIdentity . runSupplyT s+
test/BaseSpec.hs view
@@ -26,6 +26,7 @@ import           System.Environment       (setEnv) import           System.IO                (stdout) import           Test.Hspec+import           Data.Maybe               (fromJust)  import           Database.DynamoDB import           Database.DynamoDB.Filter@@ -175,7 +176,7 @@         putItem testitem1         new1 <- updateItemByKey tTest (tableKey testitem1)                                 ((iInt' +=. 5) <> (iText' =. "updated") <> (iMText' =. Nothing))-        Just new2 <- getItem Strongly tTest (tableKey testitem1)+        new2 <- fromJust <$> getItem Strongly tTest (tableKey testitem1)         liftIO $ do             new1 `shouldBe` new2             iInt new1 `shouldBe` 7
test/NestedSpec.hs view
@@ -28,6 +28,7 @@ import           System.Environment       (setEnv) import           System.IO                (stdout) import           Test.Hspec+import           Data.Maybe               (fromJust)  import           Database.DynamoDB import           Database.DynamoDB.Filter@@ -83,8 +84,8 @@             testitem2 = Test "hash" 2 inner1 Nothing Set.empty [] HMap.empty         putItem testitem1         putItem testitem2-        Just ritem1 <- getItem Strongly tTest ("hash", 1)-        Just ritem2 <- getItem Strongly tTest ("hash", 2)+        ritem1 <- fromJust <$> getItem Strongly tTest ("hash", 1)+        ritem2 <- fromJust <$> getItem Strongly tTest ("hash", 2)         liftIO $ testitem1 `shouldBe` ritem1         liftIO $ testitem2 `shouldBe` ritem2     withDb "Scan conditions" $ do