packages feed

haskus-utils 1.3 → 1.4

raw patch · 4 files changed

+44/−13 lines, 4 filesdep +hashabledep −recursion-schemesdep ~stm-containers

Dependencies added: hashable

Dependencies removed: recursion-schemes

Dependency ranges changed: stm-containers

Files

haskus-utils.cabal view
@@ -1,5 +1,5 @@ name:                haskus-utils-version:             1.3+version:             1.4 synopsis:            Haskus utility modules license:             BSD3 license-file:        LICENSE@@ -9,7 +9,7 @@ copyright:           Sylvain Henry 2018 category:            System build-type:          Simple-cabal-version:       1.21+cabal-version:       1.20  description:    Haskus utility modules.@@ -45,14 +45,14 @@       ,  containers                >= 0.5       ,  list-t                    >= 0.4       ,  stm                       >= 2.4-      ,  stm-containers            >= 0.2+      ,  stm-containers            >= 1.1       ,  vector                    >= 0.11       ,  transformers              >= 0.4       ,  mtl                       >= 2.2       ,  template-haskell          >= 2.10       ,  file-embed                >= 0.0.10       ,  extra                     >= 1.4-      ,  recursion-schemes         >= 5.0+      ,  hashable                  >= 1.2    build-tools:    ghc-options:          -Wall
src/lib/Haskus/Utils/Flow.hs view
@@ -7,6 +7,8 @@    , (<|)    , (||>)    , (<||)+   , (|||>)+   , (<|||)    -- * Monadic/applicative operators    , when    , unless@@ -20,6 +22,7 @@    , foldM_    , forM    , forM_+   , forMaybeM    , mapM    , mapM_    , sequence@@ -33,13 +36,18 @@    , whileM    -- * Variant based operators    , module Haskus.Utils.Variant.Flow+   -- * Monad transformers+   , lift    ) where  import Haskus.Utils.Variant import Haskus.Utils.Variant.Flow import Haskus.Utils.Monad+import Haskus.Utils.Maybe +import Control.Monad.Trans.Class (lift)+ -- | Apply a function (|>) :: a -> (a -> b) -> b {-# INLINE (|>) #-}@@ -67,3 +75,21 @@ f <|| x = fmap f x  infixr 0 <||++-- | Apply a function in a Functor+(|||>) :: (Functor f, Functor g) => f (g a) -> (a -> b) -> f (g b)+{-# INLINE (|||>) #-}+x |||> f = fmap (fmap f) x++infixl 0 |||>++-- | Apply a function in a Functor+(<|||) :: (Functor f, Functor g) => (a -> b) -> f (g a) -> f (g b)+{-# INLINE (<|||) #-}+f <||| x = fmap (fmap f) x++infixr 0 <|||++-- | Composition of catMaybes and forM+forMaybeM :: Monad m => [a] -> (a -> m (Maybe b)) -> m [b]+forMaybeM xs f = catMaybes <|| forM xs f
src/lib/Haskus/Utils/STM/TMap.hs view
@@ -23,13 +23,15 @@ import Prelude hiding (lookup,null)  import Haskus.Utils.STM-import qualified STMContainers.Map as SMAP-import STMContainers.Map (Key)+import qualified StmContainers.Map as SMAP import ListT (fold) import qualified ListT+import Data.Hashable  import Haskus.Utils.Maybe (fromJust,isJust,isNothing) +type Key a = (Eq a, Hashable a)+ -- | STM hashmap type TMap a b = SMAP.Map a b @@ -39,7 +41,7 @@  -- | Get the number of elements in the map size :: TMap a b -> STM Int-size = fold f 0 . SMAP.stream+size = fold f 0 . SMAP.listT    where        f n _ = return (n+1) @@ -83,7 +85,7 @@  -- | Create a list of (key,value) toList :: TMap a b -> STM [(a,b)]-toList = ListT.toList . SMAP.stream+toList = ListT.toList . SMAP.listT  -- | Get values elems :: TMap a b -> STM [b]
src/lib/Haskus/Utils/STM/TSet.hs view
@@ -3,6 +3,7 @@ -- | STM mutable set module Haskus.Utils.STM.TSet    ( TSet+   , Element    , null    , size    , member@@ -23,13 +24,15 @@ import Prelude hiding (lookup,null,map)  import Haskus.Utils.STM-import qualified STMContainers.Set as SSET-import STMContainers.Set (Element)+import qualified StmContainers.Set as SSET import ListT (ListT, fold) import qualified ListT+import Data.Hashable  import Haskus.Utils.Flow (forM_) +type Element a = (Eq a, Hashable a)+ -- | STM Set type TSet a = SSET.Set a @@ -39,7 +42,7 @@  -- | Number of elements in the set size :: TSet a -> STM Int-size = fold f 0 . SSET.stream+size = fold f 0 . SSET.listT    where        f n _ = return (n+1) @@ -72,7 +75,7 @@  -- | Convert a set into a list toList :: TSet e -> STM [e]-toList = ListT.toList . SSET.stream+toList = ListT.toList . SSET.listT  -- | Create a set from a list fromList :: Element e => [e] -> STM (TSet e)@@ -87,7 +90,7 @@  -- | Get the set as a ListT stream stream :: TSet e -> ListT STM e-stream = SSET.stream+stream = SSET.listT  -- | Perform a set union unions :: Element e => [TSet e] -> STM (TSet e)