packages feed

foldl-transduce 0.4.4.0 → 0.4.5.0

raw patch · 4 files changed

+65/−16 lines, 4 filesdep +lens-family-corePVP ok

version bump matches the API change (PVP)

Dependencies added: lens-family-core

API changes (from Hackage documentation)

+ Control.Foldl.Transduce: split :: (a -> Bool) -> Transducer a a ()

Files

CHANGELOG view
@@ -1,3 +1,7 @@+# 0.4.5.0++- added split+ # 0.4.4.0  - deprecated quiesceWith
benchmarks/benchmarks.hs view
@@ -1,8 +1,21 @@ module Main where +import Data.Foldable import qualified Control.Foldl as L-import qualified Control.Foldl.Transduce+import Control.Foldl.Transduce+import Lens.Family --- TBD+import Criterion.Main+ main :: IO ()-main = return ()+main = defaultMain [+        bgroup "sum" [+             bench "without trans" (nf +                (L.fold L.sum)+                (take 500000 (cycle [1::Int,-1])))+        ,+             bench "with trans"  (nf +                (L.fold (folds (chunksOf 1) L.list (L.handles (folding toList) L.sum)))+                (take 500000 (cycle [1::Int,-1])))+        ]        +    ]
foldl-transduce.cabal view
@@ -1,5 +1,5 @@ Name: foldl-transduce-Version: 0.4.4.0+Version: 0.4.5.0 Cabal-Version: >=1.8.0.2 Build-Type: Simple License: BSD3@@ -74,10 +74,11 @@     Type:             exitcode-stdio-1.0     HS-Source-Dirs:   benchmarks     Main-Is:          benchmarks.hs-    GHC-Options:     -O2 -Wall -rtsopts +    GHC-Options: -O2 -Wall -rtsopts       Build-Depends:         base         >= 4.4     && < 5  ,         criterion    >= 1.1.0.0 && < 1.2,+        lens-family-core >= 1.2.0       ,         foldl                           ,         foldl-transduce
src/Control/Foldl/Transduce.hs view
@@ -68,6 +68,7 @@     ,   surroundIO         -- * Splitters     ,   chunksOf+    ,   split     ,   splitAt     ,   chunkedSplitAt     ,   splitLast@@ -97,7 +98,7 @@     ,   quiesceWith     ) where -import Prelude hiding (splitAt,break)+import Prelude hiding (split,splitAt,break)  import Data.Functor import Data.Bifunctor@@ -128,7 +129,7 @@ >>> import Control.Foldl.Transduce >>> import Control.Applicative >>> import qualified Control.Comonad.Cofree as C->>> import Prelude hiding (splitAt,break)+>>> import Prelude hiding (split,splitAt,break)  -} @@ -994,25 +995,55 @@                 (Nothing,[prefix],[[suffix]])         done = mempty -data SplitWhenWhenState = -      SplitWhenConditionEncountered -    | SplitWhenConditionPending+data SplitState = +      PreviousSeparator+    | PreviousNonSeparator  {-| 		 +>>> L.fold (folds (split (==2)) L.list L.list) [1,2,2,1,1,2,1]+[[1],[],[1,1],[1]]++>>> L.fold (folds (split (==2)) L.list L.list) [2,1,1,2]+[[],[1,1],[]]++-}+split :: (a -> Bool) -> Transducer a a ()+split predicate = +    Transducer step PreviousNonSeparator done +    where+        step PreviousNonSeparator i = +            if predicate i +               then (PreviousSeparator,[],[])+               else (PreviousNonSeparator,[i],[])+        step PreviousSeparator i = +            if predicate i +               then (PreviousSeparator,[],[[]])+               else (PreviousNonSeparator,[],[[i]])+        done PreviousNonSeparator = mempty+        done PreviousSeparator = ((),[],[[]])+++data BreakWhenState = +      BreakConditionEncountered +    | BreakConditionPending++{-| 		+ >>> L.fold (bisect (break (>3)) (reify id) ignore L.list) [1..5] [1,2,3]+ -} break :: (a -> Bool) -> Transducer a a () break predicate = -    Transducer step SplitWhenConditionPending done +    Transducer step BreakConditionPending done      where-        step SplitWhenConditionPending i = +        step BreakConditionPending i =              if predicate i -               then (SplitWhenConditionEncountered,[],[[i]])-               else (SplitWhenConditionPending,[i],[])-        step SplitWhenConditionEncountered i = -               (SplitWhenConditionEncountered,[i],[])+               then (BreakConditionEncountered,[],[[i]])+               else (BreakConditionPending,[i],[])+        step BreakConditionEncountered i = +               (BreakConditionEncountered,[i],[])         done = mempty  {-| Puts the last element of the input stream (if it exists) in a separate