handle package:streamly-core

When evaluating a stream if an exception occurs, stream evaluation aborts and the specified exception handler is run with the exception as argument. The exception is caught and handled unless the handler decides to rethrow it. Note that exception handling is not applied to the stream returned by the exception handler. Observes exceptions only in the stream generation, and not in stream consumers. Inhibits stream fusion
Like Streamly.Data.Stream.handle but with one significant difference, this function observes exceptions from the consumer of the stream as well. You can also convert StreamK to Stream and use exception handling from Stream module:
>>> handle f s = StreamK.fromStream $ Stream.handle (\e -> StreamK.toStream (f e)) (StreamK.toStream s)
When unfolding Unfold m a b if an exception e occurs, unfold e using Unfold m e b. Inhibits stream fusion Pre-release
>>> import qualified Streamly.FileSystem.Handle as Handle
Read and write byte streams and array streams to and from file handles (Handle). The TextEncoding, NewLineMode, and Buffering options of the underlying GHC Handle are ignored by these APIs. Please use Streamly.Unicode.Stream module for encoding and decoding a byte stream, use stream splitting operations in Streamly.Data.Stream to create a stream of lines or to split the input stream on any other type of boundaries. To set the read or write start position use hSeek on the Handle, the before combinator may be used to do that on a streaming combinator. To restrict the length of read or write use the stream trimming operations like take. Note that a Handle is inherently stateful, therefore, we cannot use these APIs from multiple threads without serialization; reading or writing in one thread would affect the file position for other threads. For additional, experimental APIs take a look at Streamly.Internal.FileSystem.Handle module.
The fundamental singleton IO APIs are getChunk and putChunk and the fundamental stream IO APIs built on top of those are readChunksWith and writeChunks. Rest of this module is just combinatorial programming using these. We can achieve line buffering by folding lines in the input stream into a stream of arrays using Stream.splitOn or Fold.takeEndBy_ and similar operations. One can wrap the input stream in Maybe type and then use writeMaybesWith to achieve user controlled buffering.
Like handle but the exception handler is also provided with the stream that generated the exception as input. The exception handler can thus re-evaluate the stream to retry the action that failed. The exception handler can again call ghandle on it to retry the action multiple times. This is highly experimental. In a stream of actions we can map the stream with a retry combinator to retry each action on failure. Inhibits stream fusion Pre-release