Skip to content

Commit 2564635

Browse files
author
José Valim
committed
Document side-effects on stream APIs
1 parent 6570541 commit 2564635

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

lib/elixir/lib/file.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -973,7 +973,7 @@ defmodule File do
973973
of bytes given by `line_or_bytes`.
974974
975975
The returned stream will fail for the same reasons as `File.open!`.
976-
Note that the file is opened only when streaming begins.
976+
Note that the file is opened only and every time streaming begins.
977977
"""
978978
def stream!(file, mode // [], line_or_bytes // :line) do
979979
fn(acc, fun) ->
@@ -992,7 +992,7 @@ defmodule File do
992992
of bytes given by `line_or_bytes`.
993993
994994
The returned stream will fail for the same reasons as `File.open!`.
995-
Note that the file is opened only when streaming begins.
995+
Note that the file is opened only and every time streaming begins.
996996
"""
997997
def binstream!(file, mode // [], line_or_bytes // :line) do
998998
fn(fun, acc) ->

lib/elixir/lib/io.ex

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,12 +224,15 @@ defmodule IO do
224224

225225
@doc """
226226
Converts the io device into a Stream. The device is
227-
iterated line by line if :line is given or by a given
227+
iterated line by line if `:line` is given or by a given
228228
number of codepoints.
229229
230-
This reads the io as utf-8. Check out
230+
This reads the IO as utf-8. Check out
231231
`IO.binstream/2` to handle the IO as a raw binary.
232232
233+
Note that an IO stream has side effects and every time
234+
you go over the stream you may get different results.
235+
233236
## Examples
234237
235238
Here is an example on how we mimic an echo server
@@ -245,9 +248,11 @@ defmodule IO do
245248

246249
@doc """
247250
Converts the io device into a Stream. The device is
248-
iterated line by line.
251+
iterated line by line or by a number of bytes. This
252+
reads the IO as a raw binary.
249253
250-
This reads the io as a raw binary.
254+
Note that an IO stream has side effects and every time
255+
you go over the stream you may get different results.
251256
"""
252257
@spec binstream(device, :line | pos_integer) :: Enumerable.t
253258
def binstream(device, line_or_bytes) do

0 commit comments

Comments
 (0)