@@ -44,8 +44,6 @@ The meaning of these types are:
44 `a` in the IO Monad.
44 `a` in the IO Monad.
45* A `Fold IO a b` is a representation of a function that converts a stream of
45* A `Fold IO a b` is a representation of a function that converts a stream of
46 type `a` to a final accumulator of type `b` in the IO Monad.
46 type `a` to a final accumulator of type `b` in the IO Monad.
47−* An `Unfold IO a b` is a representation of a function that converts a seed
48− value of type `a` into a stream of values of type `b` in the IO Monad.
50## The Examples
48## The Examples
@@ -219,7 +217,7 @@ import qualified Streamly.Unicode.Stream as Unicode
220countArray :: Array Word8 -> IO Counts
218countArray :: Array Word8 -> IO Counts
221countArray arr =
219countArray arr =
222− Stream.unfold Array.reader arr -- Stream IO Word8
220+ Array.read arr -- Stream IO Word8
223 & Unicode.decodeLatin1 -- Stream IO Char
221 & Unicode.decodeLatin1 -- Stream IO Char
224 & Stream.fold (Fold.foldl' count (Counts 0 0 0 True)) -- IO Counts
222 & Stream.fold (Fold.foldl' count (Counts 0 0 0 True)) -- IO Counts
@@ -335,9 +333,9 @@ fetch w = threadDelay 1000000 >> return (w,w)
335-- connection is closed.
333-- connection is closed.
336lookupWords :: Socket -> IO ()
334lookupWords :: Socket -> IO ()
337lookupWords sk =
335lookupWords sk =
338− Stream.unfold Socket.reader sk -- Stream IO Word8
336+ Socket.read sk -- Stream IO Word8
339 & Unicode.decodeLatin1 -- Stream IO Char
337 & Unicode.decodeLatin1 -- Stream IO Char
340− & Stream.parseMany word -- Stream IO String
338+ & Stream.wordsBy isSpace Fold.toList -- Stream IO String
341 & Stream.parMapM cfg fetch -- Stream IO (String, String)
339 & Stream.parMapM cfg fetch -- Stream IO (String, String)
342 & fmap show -- Stream IO String
340 & fmap show -- Stream IO String
343 & Stream.intersperse "\n" -- Stream IO String
341 & Stream.intersperse "\n" -- Stream IO String
@@ -346,7 +344,6 @@ lookupWords sk =
349− word = Parser.wordBy isSpace Fold.toList
350 cfg = Stream.ordered True
347 cfg = Stream.ordered True
352serve :: Socket -> IO ()
349serve :: Socket -> IO ()
@@ -357,9 +354,9 @@ serve sk = finally (lookupWords sk) (close sk)
357-- "nc" as a client to try it out.
354-- "nc" as a client to try it out.
358main :: IO ()
355main :: IO ()
360− Stream.unfold TCP.acceptorOnPort 8091 -- Stream IO Socket
357+ TCP.accept 8091 -- Stream IO Socket
361− & Stream.parMapM id serve -- Stream IO ()
358+ & Stream.parMapM id serve -- Stream IO ()
362− & Stream.fold Fold.drain -- IO ()
359+ & Stream.fold Fold.drain -- IO ()
365### Merging Incoming Streams
362### Merging Incoming Streams
@@ -379,7 +376,6 @@ including the imports that we have omitted below.
379import Streamly.Data.Stream (Stream)
376import Streamly.Data.Stream (Stream)
380import System.IO (IOMode(AppendMode), Handle, withFile)
377import System.IO (IOMode(AppendMode), Handle, withFile)
382−import qualified Streamly.Data.Unfold as Unfold
383import qualified Streamly.Network.Socket as Socket
379import qualified Streamly.Network.Socket as Socket
384import qualified Streamly.FileSystem.Handle as Handle
380import qualified Streamly.FileSystem.Handle as Handle
@@ -388,9 +384,9 @@ import qualified Streamly.FileSystem.Handle as Handle
388-- buffering for safety.
384-- buffering for safety.
389readLines :: Socket -> Stream IO (Array Char)
385readLines :: Socket -> Stream IO (Array Char)
390readLines sk =
386readLines sk =
391− Stream.unfold Socket.reader sk -- Stream IO Word8
387+ Socket.read sk -- Stream IO Word8
392− & Unicode.decodeLatin1 -- Stream IO Char
388+ & Unicode.decodeLatin1 -- Stream IO Char
393− & Stream.foldMany line -- Stream IO (Array Char)
389+ & Stream.foldMany line -- Stream IO (Array Char)
@@ -405,7 +401,7 @@ recv sk = Stream.finallyIO (close sk) (readLines sk)
405-- streams at line boundaries and writes the merged stream to a file.
401-- streams at line boundaries and writes the merged stream to a file.
406server :: Handle -> IO ()
402server :: Handle -> IO ()
407server file =
403server file =
408− Stream.unfold TCP.acceptorOnPort 8090 -- Stream IO Socket
404+ TCP.accept 8090 -- Stream IO Socket
409 & Stream.parConcatMap (Stream.eager True) recv -- Stream IO (Array Char)
405 & Stream.parConcatMap (Stream.eager True) recv -- Stream IO (Array Char)
410 & Stream.unfoldMany Array.reader -- Stream IO Char
406 & Stream.unfoldMany Array.reader -- Stream IO Char
411 & Unicode.encodeLatin1 -- Stream IO Word8
407 & Unicode.encodeLatin1 -- Stream IO Word8