@@ -382,7 +382,7 @@ converting them to and from streams.
385−`Streamly.Fold` module provides composable left folds. A `Fold` is a consumer
385+`Streamly.Data.Fold` module provides composable left folds. A `Fold` is a consumer
386of a stream. Folds can be used to fold a stream. Folds can be composed in many
386of a stream. Folds can be used to fold a stream. Folds can be composed in many
387ways, a stream can be distributed to multiple folds, or it can be partitioned
387ways, a stream can be distributed to multiple folds, or it can be partitioned
388across multiple folds, or demultiplexed over multiple folds, or unzipped to two
388across multiple folds, or demultiplexed over multiple folds, or unzipped to two
@@ -396,9 +396,10 @@ powerful ways of composing and applying them.
396## File IO
396## File IO
398The following code snippets implement some common Unix command line utilities
398The following code snippets implement some common Unix command line utilities
399−using streamly. You can compile these with `ghc -O2
399+using streamly. You can compile these with `ghc -O2 -fspec-constr-recursive=10
400−-fspec-constr-recursive=10` and compare the performance with regular GNU
400+-fmax-worker-args=16` and compare the performance with regular GNU coreutils
401−coreutils available on your system. Source file
401+available on your system. Though many of these are not most optimal solutions
402+to keep them short and elegant. Source file
402[HandleIO.hs](https://github.com/composewell/streamly/tree/master/examples/HandleIO.hs)
403[HandleIO.hs](https://github.com/composewell/streamly/tree/master/examples/HandleIO.hs)
403in the examples directory includes these examples.
404in the examples directory includes these examples.
@@ -406,9 +407,8 @@ in the examples directory includes these examples.
406module Main where
407module Main where
408import qualified Streamly.Prelude as S
409import qualified Streamly.Prelude as S
409−import qualified Streamly.Fold as FL
410+import qualified Streamly.Data.Fold as FL
410import qualified Streamly.Memory.Array as A
411import qualified Streamly.Memory.Array as A
411−import qualified Streamly.Memory.ArrayStream as AS
412import qualified Streamly.FileSystem.Handle as FH
412import qualified Streamly.FileSystem.Handle as FH
413import qualified System.IO as FH
413import qualified System.IO as FH
@@ -431,31 +431,31 @@ withArg2 f = do
433``` haskell
433``` haskell
434−cat = S.runFold (FH.writeArrays stdout) . FH.readArrays
434+cat = S.fold (FH.writeArrays stdout) . S.unfold FH.readArrays
435main = withArg cat
435main = withArg cat
440``` haskell
440``` haskell
441−cp src dst = S.runFold (FH.writeArrays dst) $ FH.readArrays src
441+cp src dst = S.fold (FH.writeArrays dst) $ S.unfold FH.readArrays src
442main = withArg2 cp
442main = withArg2 cp
447``` haskell
447``` haskell
448−wcl = S.length . AS.splitOn 10 . FH.readArrays
448+wcl = S.length . S.splitOn (== 10) FL.drain . S.unfold FH.read
449main = withArg wcl >>= print
449main = withArg wcl >>= print
452### Average Line Length
452### Average Line Length
454``` haskell
454``` haskell
456− S.runFold avg
456+ S.fold avg
457− . S.splitWithSuffix (== 10) FL.length
457+ . S.splitOn (== 10) FL.length
458− . FH.read
458+ . S.unfold FH.read
460 where avg = (/) <$> toDouble FL.sum <*> toDouble FL.length
460 where avg = (/) <$> toDouble FL.sum <*> toDouble FL.length
461 toDouble = fmap (fromIntegral :: Int -> Double)
461 toDouble = fmap (fromIntegral :: Int -> Double)
@@ -467,10 +467,10 @@ main = withArg avgll >>= print
468``` haskell
468``` haskell
470− S.runFold (FL.classify FL.length)
470+ S.fold (FL.classify FL.length)
471 . S.map bucket
471 . S.map bucket
472− . S.splitWithSuffix (== 10) FL.length
472+ . S.splitOn (== 10) FL.length
473− . FH.read
473+ . S.unfold FH.read
476 bucket n = let i = n `div` 10 in if i > 9 then (9,n) else (i,n)
476 bucket n = let i = n `div` 10 in if i > 9 then (9,n) else (i,n)