map-reduce-folds 0.1.0.7 → 0.1.1.0
raw patch · 3 files changed
+47/−9 lines, 3 filesdep ~streamlyPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependency ranges changed: streamly
API changes (from Hackage documentation)
- Control.MapReduce.Engines.Streamly: toStreamlyFoldM :: FoldM m a b -> Fold m a b
+ Control.MapReduce.Engines.Streamly: toStreamlyFoldM :: Functor m => FoldM m a b -> Fold m a b
Files
- ChangeLog.md +3/−0
- map-reduce-folds.cabal +2/−2
- src/Control/MapReduce/Engines/Streamly.hs +42/−7
ChangeLog.md view
@@ -1,3 +1,6 @@+* version 0.1.1.0+* Changes for streamly >= 0.8+ * version 0.1.0.7 * Bumped some upper bounds in prep for ghc-9
map-reduce-folds.cabal view
@@ -1,7 +1,7 @@ cabal-version: 2.2 name: map-reduce-folds-version: 0.1.0.7+version: 0.1.1.0 build-type: Simple synopsis: foldl wrappers for map-reduce description: map-reduce-folds simplifies the building of folds to do map-reduce style computations on collections. It breaks the map/reduce into an unpacking step where items may be filtered, transformed or "melted" (made into several new items), an assign step where the unpacked items are assigned keys, a grouping step where the assigned items are grouped by key and then a reduce step which is applied to each grouped subset. Tools are provided to simplify building the individual steps and then "engines" are provided for combining them into efficient folds returning an assortment of containers. The various pieces are replicated for effectful (monadic) steps producing effectful (monadic) folds.@@ -56,7 +56,7 @@ parallel >= 3.2.2 && < 3.3, split >= 0.2.3 && < 0.3, streaming >= 0.2.2 && < 0.3,- streamly >= 0.7.0 && < 0.8+ streamly >= 0.7.0 && < 0.9 hs-source-dirs: src default-language: Haskell2010
src/Control/MapReduce/Engines/Streamly.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE CPP #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE GADTs #-}@@ -13,7 +14,7 @@ {-# LANGUAGE AllowAmbiguousTypes #-} {-# LANGUAGE TypeApplications #-} {-# LANGUAGE BangPatterns #-}-{-# OPTIONS_GHC -fwarn-incomplete-patterns #-}+{-# OPTIONS_GHC -O2 -fwarn-incomplete-patterns #-} {-| Module : Control.MapReduce.Engines.Streams Description : map-reduce-folds builders@@ -81,10 +82,23 @@ import qualified Data.HashTable.Class as HT import qualified Data.HashTable.ST.Cuckoo as HTC import qualified Data.List.NonEmpty as LNE-import qualified Data.Maybe as Maybe +import qualified Data.Maybe as Maybe import qualified Data.Map.Strict as MS import qualified Data.Sequence as Seq+#if MIN_VERSION_streamly(0,8,0) import qualified Streamly.Prelude as S+import qualified Streamly.Internal.Data.Fold as SF+import Streamly.Prelude ( SerialT+ , WSerialT+ , AheadT+ , AsyncT+ , WAsyncT+ , ParallelT+ , MonadAsync+ , IsStream+ )+#else+import qualified Streamly.Prelude as S import qualified Streamly as S import qualified Streamly.Internal.Data.Fold as SF import Streamly ( SerialT@@ -96,15 +110,36 @@ , MonadAsync , IsStream )+import qualified Streamly.Internal.Data.Parser.ParserK.Type as Streamly+#endif +#if MIN_VERSION_streamly(0,8,0)+fromEffect :: (Monad m, IsStream t) => m a -> t m a+fromEffect = S.fromEffect+{-# INLINE fromEffect #-}+ -- | convert a Control.Foldl FoldM into a Streamly.Data.Fold fold+toStreamlyFoldM :: Functor m => FL.FoldM m a b -> SF.Fold m a b+toStreamlyFoldM (FL.FoldM step start done) = SF.mkFoldM step' (SF.Partial <$> start) done where+ step' s a = SF.Partial <$> step s a++-- | convert a Control.Foldl Fold into a Streamly.Data.Fold fold+toStreamlyFold :: Monad m => FL.Fold a b -> SF.Fold m a b+toStreamlyFold (FL.Fold step start done) = SF.mkFold step' (SF.Partial start) done where+ step' s a = SF.Partial $ step s a+#else+fromEffect :: (Monad m, IsStream t) => m a -> t m a+fromEffect = Streamly.yieldM+{-# INLINE fromEffect #-}++-- | convert a Control.Foldl FoldM into a Streamly.Data.Fold fold toStreamlyFoldM :: FL.FoldM m a b -> SF.Fold m a b toStreamlyFoldM (FL.FoldM step start done) = SF.mkFold step start done -- | convert a Control.Foldl Fold into a Streamly.Data.Fold fold toStreamlyFold :: Monad m => FL.Fold a b -> SF.Fold m a b toStreamlyFold (FL.Fold step start done) = SF.mkPure step start done-+#endif -- | unpack for streamly based map/reduce unpackStream :: S.IsStream t => MRC.Unpack x y -> t Identity x -> t Identity y@@ -208,7 +243,7 @@ => S.SerialT m (k, c) -> S.SerialT m (k, Seq.Seq c) groupByHashableKey s = do- lkc <- S.yieldM (S.toList s)+ lkc <- fromEffect (S.toList s) let hm = HMS.fromListWith (<>) $ fmap (second $ Seq.singleton) lkc HMS.foldrWithKey (\k lc s' -> S.cons (k, lc) s') S.nil hm {-# INLINABLE groupByHashableKey #-}@@ -219,7 +254,7 @@ groupByOrderedKey :: (Monad m, Ord k) => S.SerialT m (k, c) -> S.SerialT m (k, Seq.Seq c) groupByOrderedKey s = do- lkc <- S.yieldM (S.toList s)+ lkc <- fromEffect (S.toList s) let hm = MS.fromListWith (<>) $ fmap (second $ Seq.singleton) lkc MS.foldrWithKey (\k lc s' -> S.cons (k, lc) s') S.nil hm {-# INLINABLE groupByOrderedKey #-}@@ -231,7 +266,7 @@ => S.SerialT m (k, c) -> S.SerialT m (k, Seq.Seq c) groupByHashableKeyST st = do- lkc <- S.yieldM (S.toList st)+ lkc <- fromEffect (S.toList st) ST.runST $ do hm <- (MRE.fromListWithHT @HTC.HashTable) (<>) $ fmap (second Seq.singleton) lkc@@ -246,7 +281,7 @@ => S.SerialT m (k, c) -> S.SerialT m (k, Seq.Seq c) groupByDiscriminatedKey s = do- lkc <- S.yieldM (S.toList s)+ lkc <- fromEffect (S.toList s) let g :: LNE.NonEmpty (k, c) -> (k, Seq.Seq c) g x = let k = fst (LNE.head x) in (k, F.fold $ fmap (Seq.singleton . snd) x) S.fromFoldable $ Maybe.catMaybes . fmap (fmap g . LNE.nonEmpty) $ DG.groupWith fst lkc