APIText.Writer
Text.Writer
Writing text to a byte writer through an encoding.
A text writer encodes each string it is given, as a whole, before emitting
any of it, so a string with an unrepresentable character emits nothing;
earlier writes stay written. The scopes flush when their callback returns,
including when it returns an Err value, but not when it aborts. The byte
writer’s own buffering still decides when bytes reach its sink.
Writer
type Writer eSource
A text writer whose operations perform e.
borrow
borrow : Writer e -> (Writer {#s} ->{#s} a) ->{e} aSource
over for a nested encoder that leaves the flush boundary to its caller:
it performs no final flush, though flush still reaches the parent.
collecting
collecting : (Writer {#s} ->{#s} a) ->{e} (a, String)Source
Runs action with a text writer that keeps everything written in memory,
and answers the result with that text. Its flush does nothing. With no
other effects in the callback, the call is pure.
import Text.Writer
written =
Text.Writer.collecting { writer ->
Text.Writer.write writer "ab"
Text.Writer.writeChar writer 'c'
}
written == ((), "abc")
flush
flush : Writer e ->{e} ()Source
Flushes the underlying byte writer.
over
over : Writer e -> (Writer {#s} ->{#s} a) ->{e} aSource
Runs action with a UTF-8 text writer over parent, which cannot fail to
encode, and flushes when action returns.
overWith
overWith : Encoding -> Writer e -> (Writer {#s} ->{#s} a) ->{Fail Error, e} aSource
Runs action with a text writer over parent in encoding. An
unrepresentable character fails with Fail Encoding.Error; handle it
around the scope, or use tryWrite.
tryWrite
tryWrite : Writer e -> String ->{e} Result Error ()Source
Writes the text, answering an encoding error as a value instead of failing, so a consumer can recover from one failed write.
write
write : Writer e -> String ->{e} ()Source
Writes the text.
writeChar
writeChar : Writer e -> Char ->{e} ()Source
Writes one character.
