on master help sign in
Enable FileSystem.File module example
commitdb0a150df4b6712a2aced70284e94b043e6062d7 authorHarendra Kumar <harendra.kumar@gmail.com> dateThu 26 Sep 2019, 01:35 (7 years ago) parentb8b3e17
2 files changed+10−9
examples/FileIOExamples.hs+9−8 streamly.cabal+1−1
examples/FileIOExamples.hs+9−8
@@ -1,7 +1,8 @@
11import qualified Streamly.Prelude as S
2−import qualified Streamly.Fold as FL
2+import qualified Streamly.Data.Fold as FL
33import qualified Streamly.Memory.Array as A
4−import qualified Streamly.FileSystem.File as File
4+import qualified Streamly.Internal.Prelude as IP
5+import qualified Streamly.Internal.FileSystem.File as File
56
67import Data.Char (ord)
78import System.Environment (getArgs)
@@ -20,25 +21,25 @@ ord' = (fromIntegral . ord)
2021
2122wcl :: FilePath -> IO ()
2223wcl src = print =<< (S.length
23− $ FL.splitSuffixBy (== ord' '\n') FL.drain
24+ $ S.splitOnSuffix (== ord' '\n') FL.drain
2425 $ File.read src)
2526
2627grepc :: String -> FilePath -> IO ()
2728grepc pat src = print . (subtract 1) =<< (S.length
28− $ FL.splitOn (A.fromList (map ord' pat)) FL.drain
29+ $ IP.splitOnSeq (A.fromList (map ord' pat)) FL.drain
2930 $ File.read src)
3031
3132avgll :: FilePath -> IO ()
32−avgll src = print =<< (FL.foldl' avg
33− $ FL.splitSuffixBy (== ord' '\n') FL.length
33+avgll src = print =<< (S.runFold avg
34+ $ S.splitOnSuffix (== ord' '\n') FL.length
3435 $ File.read src)
3536 where avg = (/) <$> toDouble FL.sum <*> toDouble FL.length
3637 toDouble = fmap (fromIntegral :: Int -> Double)
3738
3839llhisto :: FilePath -> IO ()
39−llhisto src = print =<< (FL.foldl' (FL.classify FL.length)
40+llhisto src = print =<< (S.runFold (FL.classify FL.length)
4041 $ S.map bucket
41− $ FL.splitSuffixBy (== ord' '\n') FL.length
42+ $ S.splitOnSuffix (== ord' '\n') FL.length
4243 $ File.read src)
4344 where
4445 bucket n = let i = n `div` 10 in if i > 9 then (9,n) else (i,n)
streamly.cabal+1−1
@@ -866,7 +866,7 @@ executable FileIOExamples
866866 main-is: FileIOExamples.hs
867867 hs-source-dirs: examples
868868 if flag(examples) || flag(examples-sdl)
869− buildable: False
869+ buildable: True
870870 build-Depends:
871871 streamly
872872 , base >= 4.8 && < 5