on master help sign in
Add stream read ops for Array/Handle/Socket/TCP
3fdf183Harendra Kumar
core/src/Streamly/Data/Array.hs+7−3
@@ -66,6 +66,10 @@ module Streamly.Data.Array
66 , unpin
66 , unpin
67 , isPinned
67 , isPinned
68
68
69+ -- * Streams
70+ , read
71+ , readRev
72+
69 -- * Unfolds
73 -- * Unfolds
70 , reader
74 , reader
71 , readerRev
75 , readerRev
@@ -87,7 +91,7 @@ where
87
91
88#include "inline.hs"
92#include "inline.hs"
89
93
90−import Streamly.Internal.Data.Array hiding (read, readRev)
94+import Streamly.Internal.Data.Array
91import Streamly.Internal.Data.Unbox (Unbox (..))
95import Streamly.Internal.Data.Unbox (Unbox (..))
92
96
93import Prelude hiding (read, length)
97import Prelude hiding (read, length)
@@ -106,7 +110,7 @@ import Prelude hiding (read, length)
106--
110--
107-- Convert array to stream, and fold the stream:
111-- Convert array to stream, and fold the stream:
108--
112--
109−-- >>> fold f arr = Stream.unfold Array.reader arr & Stream.fold f
113+-- >>> fold f arr = Array.read arr & Stream.fold f
110-- >>> fold Fold.sum (Array.fromList [1,2,3::Int])
114-- >>> fold Fold.sum (Array.fromList [1,2,3::Int])
111-- 6
115-- 6
112--
116--
@@ -114,7 +118,7 @@ import Prelude hiding (read, length)
114--
118--
115-- Convert array to stream, transform, and fold back to array:
119-- Convert array to stream, transform, and fold back to array:
116--
120--
117−-- >>> amap f arr = Stream.unfold Array.reader arr & fmap f & Stream.fold Array.write
121+-- >>> amap f arr = Array.read arr & fmap f & Stream.fold Array.write
118-- >>> amap (+1) (Array.fromList [1,2,3::Int])
122-- >>> amap (+1) (Array.fromList [1,2,3::Int])
119-- fromList [2,3,4]
123-- fromList [2,3,4]
120--
124--
core/src/Streamly/FileSystem/Handle.hs+7−6
@@ -81,13 +81,13 @@ module Streamly.FileSystem.Handle
81 -- position of the file handle. The stream ends as soon as EOF is
81 -- position of the file handle. The stream ends as soon as EOF is
82 -- encountered.
82 -- encountered.
83
83
84− -- -- *** Streams
84+ -- *** Streams
85− -- , read
85+ , read
86− -- , readWith
86+ , readWith
87− -- , readChunks
87+ , readChunks
88− -- , readChunksWith
88+ , readChunksWith
89
89
90− -- -- *** Unfolds
90+ -- *** Unfolds
91 , reader
91 , reader
92 , readerWith
92 , readerWith
93 , chunkReader
93 , chunkReader
@@ -112,5 +112,6 @@ module Streamly.FileSystem.Handle
112where
112where
113
113
114import Streamly.Internal.FileSystem.Handle
114import Streamly.Internal.FileSystem.Handle
115+import Prelude hiding (read)
115
116
116#include "DocTestFileSystemHandle.hs"
117#include "DocTestFileSystemHandle.hs"
src/Streamly/Network/Inet/TCP.hs+6−6
@@ -15,8 +15,13 @@
15module Streamly.Network.Inet.TCP
15module Streamly.Network.Inet.TCP
16 (
16 (
17 -- * Accept Connections
17 -- * Accept Connections
18+ -- ** Streams
19+ acceptOnAddr
20+ , acceptOnPort
21+ , acceptOnPortLocal
22+
18 -- ** Unfolds
23 -- ** Unfolds
19− acceptorOnAddr
24+ , acceptorOnAddr
20 , acceptorOnPort
25 , acceptorOnPort
21 , acceptorOnPortLocal
26 , acceptorOnPortLocal
22
27
@@ -51,9 +56,4 @@ module Streamly.Network.Inet.TCP
51 )
56 )
52where
57where
53
58
54−import Control.Monad.IO.Class (MonadIO(..))
55−import Data.Word (Word8)
56−import Network.Socket (Socket, PortNumber)
57−import Streamly.Internal.Data.Unfold (Unfold(..))
58−
59import Streamly.Internal.Network.Inet.TCP
59import Streamly.Internal.Network.Inet.TCP
src/Streamly/Network/Socket.hs+11−6
@@ -50,11 +50,11 @@
50-- in server spec addr
50-- in server spec addr
51-- where
51-- where
52-- server spec addr =
52-- server spec addr =
53−-- Stream.unfold Socket.acceptor (maxListenQueue, spec, addr)
53+-- Socket.accept maxListenQueue spec addr
54-- & Stream.parMapM (Stream.eager True) (Socket.forSocketM echo)
54-- & Stream.parMapM (Stream.eager True) (Socket.forSocketM echo)
55-- & Stream.fold Fold.drain
55-- & Stream.fold Fold.drain
56-- echo sk =
56-- echo sk =
57−-- Stream.unfold Socket.chunkReader sk -- Stream IO (Array Word8)
57+-- Socket.readChunks sk -- Stream IO (Array Word8)
58-- & Stream.fold (Socket.writeChunks sk) -- IO ()
58-- & Stream.fold (Socket.writeChunks sk) -- IO ()
59-- :}
59-- :}
60--
60--
@@ -95,12 +95,19 @@ module Streamly.Network.Socket
95 SockSpec(..)
95 SockSpec(..)
96
96
97 -- * Accept Connections
97 -- * Accept Connections
98+ , accept
98 , acceptor
99 , acceptor
99
100
100 -- * Reads
101 -- * Reads
101 -- ** Singleton
102 -- ** Singleton
102 , getChunk
103 , getChunk
103
104
105+ -- ** Streams
106+ , read
107+ , readWith
108+ , readChunks
109+ , readChunksWith
110+
104 -- ** Unfolds
111 -- ** Unfolds
105 , reader
112 , reader
106 , readerWith
113 , readerWith
@@ -130,11 +137,9 @@ module Streamly.Network.Socket
130 )
137 )
131where
138where
132
139
133−import Control.Monad.IO.Class (MonadIO(..))
134import Data.Word (Word8)
140import Data.Word (Word8)
135−import Network.Socket (Socket, SockAddr)
141+import Network.Socket (Socket)
136−import Streamly.Internal.Data.Unfold (Unfold(..))
142+import Streamly.Data.Array (Array)
137−import Streamly.Internal.Data.Array (Array(..))
138import Streamly.Data.MutByteArray (Unbox)
143import Streamly.Data.MutByteArray (Unbox)
139
144
140import Streamly.Internal.Network.Socket
145import Streamly.Internal.Network.Socket