packages feed

deferred-folds 0.6.10 → 0.6.11

raw patch · 3 files changed

+15/−4 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ DeferredFolds.Unfold: mapFoldInput :: (forall x. Fold b x -> Fold a x) -> Unfold a -> Unfold b
+ DeferredFolds.UnfoldM: mapFoldMInput :: Monad m => (forall x. FoldM m b x -> FoldM m a x) -> UnfoldM m a -> UnfoldM m b

Files

deferred-folds.cabal view
@@ -1,7 +1,7 @@ name:   deferred-folds version:-  0.6.10+  0.6.11 category:   Folding synopsis:
library/DeferredFolds/Unfold.hs view
@@ -1,7 +1,7 @@ module DeferredFolds.Unfold where -import DeferredFolds.Prelude+import DeferredFolds.Prelude hiding (fold) import qualified DeferredFolds.Prelude as A import qualified DeferredFolds.UnfoldM as B import qualified Data.Map.Strict as C@@ -125,11 +125,17 @@ unfoldM :: B.UnfoldM Identity input -> Unfold input unfoldM (B.UnfoldM runFoldM) = Unfold (\ step init -> runIdentity (runFoldM (\ a b -> return (step a b)) init)) +{-| Lift a fold input mapping function into a mapping of unfolds -}+{-# INLINE mapFoldInput #-}+mapFoldInput :: (forall x. Fold b x -> Fold a x) -> Unfold a -> Unfold b+mapFoldInput newFold unfold = Unfold $ \ step init -> fold (newFold (Fold step init id)) unfold+ {-| Construct from any foldable -} {-# INLINE foldable #-} foldable :: Foldable foldable => foldable a -> Unfold a foldable foldable = Unfold (\ step init -> A.foldl' step init foldable) +{-| Filter the values given a predicate -} {-# INLINE filter #-} filter :: (a -> Bool) -> Unfold a -> Unfold a filter test (Unfold run) = Unfold (\ step -> run (\ state element -> if test element then step state element else state))
library/DeferredFolds/UnfoldM.hs view
@@ -1,7 +1,7 @@ module DeferredFolds.UnfoldM where -import DeferredFolds.Prelude hiding (mapM_)+import DeferredFolds.Prelude hiding (mapM_, foldM) import qualified DeferredFolds.Prelude as A import qualified Data.ByteString.Internal as ByteString import qualified Data.ByteString.Short.Internal as ShortByteString@@ -105,6 +105,11 @@     finalState <- foldlM' step initialState view     extract finalState +{-| Lift a fold input mapping function into a mapping of unfolds -}+{-# INLINE mapFoldMInput #-}+mapFoldMInput :: Monad m => (forall x. FoldM m b x -> FoldM m a x) -> UnfoldM m a -> UnfoldM m b+mapFoldMInput newFoldM unfoldM = UnfoldM $ \ step init -> foldM (newFoldM (FoldM step (return init) return)) unfoldM+ {-| Construct from any foldable -} {-# INLINE foldable #-} foldable :: (Monad m, Foldable foldable) => foldable a -> UnfoldM m a@@ -120,7 +125,7 @@ foldrRunner :: Monad m => (forall x. (a -> x -> x) -> x -> x) -> UnfoldM m a foldrRunner run = UnfoldM (\ stepM -> run (\ x k z -> stepM z x >>= k) return) -{-| Filter -}+{-| Filter the values given a predicate -} {-# INLINE filter #-} filter :: Monad m => (a -> m Bool) -> UnfoldM m a -> UnfoldM m a filter test (UnfoldM run) = UnfoldM (\ step -> run (\ state element -> test element >>= bool (return state) (step state element)))