File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -70,6 +70,7 @@ module Streaming.Prelude (
7070 , stdinLn
7171 , readLn
7272 , fromHandle
73+ , readFile
7374 , iterate
7475 , iterateM
7576 , repeat
@@ -91,6 +92,7 @@ module Streaming.Prelude (
9192 , mapM_
9293 , print
9394 , toHandle
95+ , writeFile
9496 , effects
9597 , erase
9698 , drained
@@ -2365,7 +2367,33 @@ stdoutLn = loop
23652367 Right () -> loop rest
23662368{-# INLINABLE stdoutLn #-}
23672369
2370+ {-| Read the lines of a file, using a function of the type: \'@'Stream' ('Of' 'String') 'IO' () -> 'IO' a@\'
2371+ to turn the stream into a value of type \''IO' a\'.
23682372
2373+ >>> S.writeFile "lines.txt" $ S.take 2 S.stdinLn
2374+ hello<Enter>
2375+ world<Enter>
2376+ >>> S.print $ S.readFile "lines.txt"
2377+ "hello"
2378+ "world"
2379+
2380+ -}
2381+ readFile :: FilePath -> (Stream (Of String ) IO () -> IO a ) -> IO a
2382+ readFile f s = IO. withFile f IO. ReadMode $ \ h -> s (fromHandle h)
2383+
2384+ {-| Write a series of 'String's as lines to a file.
2385+
2386+ >>> S.writeFile "lines.txt" $ S.take 2 S.stdinLn
2387+ hello<Enter>
2388+ world<Enter>
2389+
2390+ >>> S.stdoutLn $ S.readFile "lines.txt"
2391+ hello
2392+ world
2393+
2394+ -}
2395+ writeFile :: FilePath -> Stream (Of String ) IO r -> IO r
2396+ writeFile f = IO. withFile f IO. WriteMode . flip toHandle
23692397
23702398{-| Write 'String's to 'IO.stdout' using 'putStrLn'
23712399
You can’t perform that action at this time.
0 commit comments