foldl-transduce 0.0.1 → 0.1.0.0
raw patch · 2 files changed
+20/−21 lines, 2 filesdep −profunctorsPVP ok
version bump matches the API change (PVP)
Dependencies removed: profunctors
API changes (from Hackage documentation)
- Control.Foldl.Transduce: generalize' :: Monad m => Transducer i o r -> TransducerM m i o r
- Control.Foldl.Transduce: simplify' :: TransducerM Identity i o r -> Transducer i o r
+ Control.Foldl.Transduce: generalizeTransducer :: Monad m => Transducer i o r -> TransducerM m i o r
+ Control.Foldl.Transduce: simplifyTransducer :: TransducerM Identity i o r -> Transducer i o r
- Control.Foldl.Transduce: transduce' :: (x -> y -> z) -> Transducer i o x -> Fold o y -> Fold i z
+ Control.Foldl.Transduce: transduce' :: Transducer i o x -> Fold o y -> Fold i (x, y)
- Control.Foldl.Transduce: transduceM' :: Monad m => (x -> y -> z) -> TransducerM m i o x -> FoldM m o y -> FoldM m i z
+ Control.Foldl.Transduce: transduceM' :: Monad m => TransducerM m i o x -> FoldM m o y -> FoldM m i (x, y)
Files
- foldl-transduce.cabal +2/−3
- src/Control/Foldl/Transduce.hs +18/−18
foldl-transduce.cabal view
@@ -1,5 +1,5 @@ Name: foldl-transduce-Version: 0.0.1+Version: 0.1.0.0 Cabal-Version: >=1.8.0.2 Build-Type: Simple License: BSD3@@ -9,7 +9,7 @@ Maintainer: diaz_carrete@yahoo.com Bug-Reports: https://github.com/danidiaz/foldl-transduce/issues Synopsis: Transducers for folds from foldl.-Description: Stateful transducers and streaming-preserving grouping operations for the folds from the foldl package.+Description: Stateful transducers and streaming-preserving grouping operations for the folds in the foldl package. Category: Control Source-Repository head Type: git@@ -23,7 +23,6 @@ text >= 0.11.2.0 && < 1.3 , transformers >= 0.2.0.0 && < 0.5 , containers < 0.6 ,- profunctors < 5.2 , semigroupoids >= 5.0 , foldl >= 1.1 && < 2 , comonad == 4.*
src/Control/Foldl/Transduce.hs view
@@ -22,8 +22,8 @@ , surround , surroundIO -- * Transducer utilities- , generalize'- , simplify'+ , generalizeTransducer+ , simplifyTransducer , foldify , foldifyM , chokepoint @@ -87,8 +87,8 @@ {-| A (possibly stateful) transformation on the inputs of a 'Fold'. - Functions constructed with combinators like 'L.premap' of "Control.Foldl"- also typecheck as 'Transduction'.+ Functions constructed with combinators like 'L.premap' or 'L.handles' from+ "Control.Foldl" also typecheck as a 'Transduction'. -} type Transduction a b = forall x. Fold b x -> Fold a x @@ -138,16 +138,16 @@ [1,2,3,4,5,6,7] -} transduce :: Transducer i o r -> Transduction i o -transduce = transduce' (flip const) +transduce t = fmap snd . (transduce' t) -{-| Generalized version of 'transduce' than doesn't ignore the return value of+{-| Generalized version of 'transduce' that preserves the return value of the 'Transducer'. ->>> L.fold (transduce' (,) (Transducer (\_ i -> ((),[i])) () (\_ -> ('r',[]))) L.list) [1..7]+>>> L.fold (transduce' (Transducer (\_ i -> ((),[i])) () (\_ -> ('r',[]))) L.list) [1..7] ('r',[1,2,3,4,5,6,7]) -}-transduce' :: (x -> y -> z) -> Transducer i o x -> Fold o y -> Fold i z-transduce' f (Transducer wstep wstate wdone) (Fold fstep fstate fdone) =+transduce' :: Transducer i o x -> Fold o y -> Fold i (x,y)+transduce' (Transducer wstep wstate wdone) (Fold fstep fstate fdone) = Fold step (Pair wstate fstate) done where step (Pair ws fs) i = @@ -157,14 +157,14 @@ done (Pair ws fs) = let (wr,os) = wdone ws in - f wr (fdone (foldl' fstep fs os))+ (,) wr (fdone (foldl' fstep fs os)) transduceM :: Monad m => TransducerM m i o r -> TransductionM m i o -transduceM = transduceM' (flip const)+transduceM t = fmap snd . (transduceM' t) -transduceM' :: Monad m => (x -> y -> z) -> TransducerM m i o x -> FoldM m o y -> FoldM m i z-transduceM' f (TransducerM wstep wstate wdone) (FoldM fstep fstate fdone) =+transduceM' :: Monad m => TransducerM m i o x -> FoldM m o y -> FoldM m i (x,y)+transduceM' (TransducerM wstep wstate wdone) (FoldM fstep fstate fdone) = FoldM step (liftM2 Pair wstate fstate) done where step (Pair ws fs) i = do@@ -174,7 +174,7 @@ done (Pair ws fs) = do (wr,os) <- wdone ws fr <- fdone =<< foldlM fstep fs os- return $! f wr fr+ return $! (,) wr fr ------------------------------------------------------------------------------ @@ -227,8 +227,8 @@ {-| Generalize a 'Transducer' to a 'TransducerM'. -}-generalize' :: Monad m => Transducer i o r -> TransducerM m i o r-generalize' (Transducer step begin done) = TransducerM step' begin' done'+generalizeTransducer :: Monad m => Transducer i o r -> TransducerM m i o r+generalizeTransducer (Transducer step begin done) = TransducerM step' begin' done' where step' x a = return (step x a) begin' = return begin@@ -237,8 +237,8 @@ {-| Simplify a pure 'TransducerM' to a 'Transducer'. -}-simplify' :: TransducerM Identity i o r -> Transducer i o r-simplify' (TransducerM step begin done) = Transducer step' begin' done' where+simplifyTransducer :: TransducerM Identity i o r -> Transducer i o r+simplifyTransducer (TransducerM step begin done) = Transducer step' begin' done' where step' x a = runIdentity (step x a) begin' = runIdentity begin done' x = runIdentity (done x)