on master help sign in
Fix some examples in the readme
63bd9d3Harendra Kumar
README.md+16−16
@@ -382,7 +382,7 @@ converting them to and from streams.
382
382
383## Folds
383## Folds
384
384
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
397
397
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.
404
405
@@ -406,9 +407,8 @@ in the examples directory includes these examples.
406module Main where
407module Main where
407
408
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
414
414
@@ -431,31 +431,31 @@ withArg2 f = do
431### cat
431### cat
432
432
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
436```
436```
437
437
438### cp
438### cp
439
439
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
443```
443```
444
444
445### wc -l
445### wc -l
446
446
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
450```
450```
451
451
452### Average Line Length
452### Average Line Length
453
453
454``` haskell
454``` haskell
455−avgll =
455+avgll =
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
459
459
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
467
467
468``` haskell
468``` haskell
469llhisto =
469llhisto =
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
474
474
475 where
475 where
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)
src/Streamly/FileSystem/Handle.hs+1
@@ -65,6 +65,7 @@ module Streamly.FileSystem.Handle
65 -- , readFrames
65 -- , readFrames
66 , readInChunksOf
66 , readInChunksOf
67 , readArraysOf
67 , readArraysOf
68+ , readArrays
68
69
69 -- ** Write to Handle
70 -- ** Write to Handle
70 -- | 'TextEncoding', 'NewLineMode', and 'Buffering' options of the
71 -- | 'TextEncoding', 'NewLineMode', and 'Buffering' options of the