-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Description
In some situations, one may want to do perform some actions with side-effects in streams. For example, you may want to log each value as they pass through the pipe. Or write the data to a socket/file (or different sockets). This is a short discussion around the API to enable these operations.
Stream.each/2
Receives an enumerable and a function returns a stream that executes the given function for each element but doesn't affect the result.
@spec each(Enumerable.t, (term -> term)) :: Stream.Lazy.tFile.stream_to!/3 and File.binstream_to!/3
Receives an enumerable and a file with its mode (optional) and returns a stream that will open the file, write to it and close the file once streaming is done.
@spec stream_to(Enumerable.t, file :: binary | char_list, mode :: list) :: Stream.Lazy.tStream.run/1
We need a way to run a stream for its side-effects (we don't care about the results). Enum.force/1 has been proposed in the past but I believe Stream.run/1 is a better name for that it actually does.
Feedback is welcome!