on master help sign in
Enable FileSystem.File module example
db0a150Harendra Kumar
examples/FileIOExamples.hs+9−8
@@ -1,7 +1,8 @@
1import qualified Streamly.Prelude as S
1import qualified Streamly.Prelude as S
2−import qualified Streamly.Fold as FL
2+import qualified Streamly.Data.Fold as FL
3import qualified Streamly.Memory.Array as A
3import 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
5
6
6import Data.Char (ord)
7import Data.Char (ord)
7import System.Environment (getArgs)
8import System.Environment (getArgs)
@@ -20,25 +21,25 @@ ord' = (fromIntegral . ord)
20
21
21wcl :: FilePath -> IO ()
22wcl :: FilePath -> IO ()
22wcl src = print =<< (S.length
23wcl src = print =<< (S.length
23− $ FL.splitSuffixBy (== ord' '\n') FL.drain
24+ $ S.splitOnSuffix (== ord' '\n') FL.drain
24 $ File.read src)
25 $ File.read src)
25
26
26grepc :: String -> FilePath -> IO ()
27grepc :: String -> FilePath -> IO ()
27grepc pat src = print . (subtract 1) =<< (S.length
28grepc 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
29 $ File.read src)
30 $ File.read src)
30
31
31avgll :: FilePath -> IO ()
32avgll :: FilePath -> IO ()
32−avgll src = print =<< (FL.foldl' avg
33+avgll src = print =<< (S.runFold avg
33− $ FL.splitSuffixBy (== ord' '\n') FL.length
34+ $ S.splitOnSuffix (== ord' '\n') FL.length
34 $ File.read src)
35 $ File.read src)
35 where avg = (/) <$> toDouble FL.sum <*> toDouble FL.length
36 where avg = (/) <$> toDouble FL.sum <*> toDouble FL.length
36 toDouble = fmap (fromIntegral :: Int -> Double)
37 toDouble = fmap (fromIntegral :: Int -> Double)
37
38
38llhisto :: FilePath -> IO ()
39llhisto :: FilePath -> IO ()
39−llhisto src = print =<< (FL.foldl' (FL.classify FL.length)
40+llhisto src = print =<< (S.runFold (FL.classify FL.length)
40 $ S.map bucket
41 $ S.map bucket
41− $ FL.splitSuffixBy (== ord' '\n') FL.length
42+ $ S.splitOnSuffix (== ord' '\n') FL.length
42 $ File.read src)
43 $ File.read src)
43 where
44 where
44 bucket n = let i = n `div` 10 in if i > 9 then (9,n) else (i,n)
45 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
866 main-is: FileIOExamples.hs
866 main-is: FileIOExamples.hs
867 hs-source-dirs: examples
867 hs-source-dirs: examples
868 if flag(examples) || flag(examples-sdl)
868 if flag(examples) || flag(examples-sdl)
869− buildable: False
869+ buildable: True
870 build-Depends:
870 build-Depends:
871 streamly
871 streamly
872 , base >= 4.8 && < 5
872 , base >= 4.8 && < 5