Documentation ¶
Overview ¶
Package io contains WDTE functions for dealing with files and other types of data streams.
Index ¶
- Variables
- func Close(frame wdte.Frame, args ...wdte.Func) wdte.Func
- func Combine(frame wdte.Frame, args ...wdte.Func) wdte.Func
- func Copy(frame wdte.Frame, args ...wdte.Func) wdte.Func
- func Lines(frame wdte.Frame, args ...wdte.Func) wdte.Func
- func ReadString(frame wdte.Frame, args ...wdte.Func) wdte.Func
- func Runes(frame wdte.Frame, args ...wdte.Func) wdte.Func
- func Scan(frame wdte.Frame, args ...wdte.Func) wdte.Func
- func Seek(frame wdte.Frame, args ...wdte.Func) wdte.Func
- func String(frame wdte.Frame, args ...wdte.Func) wdte.Func
- func Words(frame wdte.Frame, args ...wdte.Func) wdte.Func
- func Write(frame wdte.Frame, args ...wdte.Func) wdte.Func
- func Writeln(frame wdte.Frame, args ...wdte.Func) wdte.Func
- type Reader
- type Writer
Constants ¶
This section is empty.
Variables ¶
var ( Stdin io.Reader = os.Stdin Stdout io.Writer = os.Stdout Stderr io.Writer = os.Stderr )
These variables are what are returned by the corresponding functions in this package. If a client wants to globally redirect input or output, they may simply change these variables.
var Scope = wdte.S().Map(map[wdte.ID]wdte.Func{ "stdin": stdin{}, "stdout": stdout{}, "stderr": stderr{}, "seek": wdte.GoFunc(Seek), "close": wdte.GoFunc(Close), "combine": wdte.GoFunc(Combine), "copy": wdte.GoFunc(Copy), "readString": wdte.GoFunc(ReadString), "string": wdte.GoFunc(String), "lines": wdte.GoFunc(Lines), "words": wdte.GoFunc(Words), "scan": wdte.GoFunc(Scan), "runes": wdte.GoFunc(Runes), "write": wdte.GoFunc(Write), "writeln": wdte.GoFunc(Writeln), })
Scope is a scope containing the functions in this package.
Functions ¶
func Close ¶
Close is a WDTE function with the following signatures:
close c
Returns c after closing it.
func Combine ¶
Combine is a WDTE function with the following signatures:
combine a ... (combine a) ...
If the arguments passed are readers, it returns a reader that reads each until EOF before continuing to the next, and finally yielding EOF itself when the last reader does.
If the arguments passed are writers, it returns a writer that writes each write to all of them in turn, only returning when they have all returned.
func Copy ¶
Copy is a WDTE function with the following signatures:
copy w r (copy w) r copy r w (copy r) w
Copies from the reader r into the writer w until r yields EOF. Returns whichever argument was given second.
The reason for this return discrepency is to allow both variants of the function to be used more easily in chains. For example, both of the following work:
stdout -> copy stdin -> ... # Later elements will be given stdout. stdin -> copy stdout -> ... # Later elements will be given stdin.
func Lines ¶
Lines is a WDTE function with the following signature:
lines r
Returns a stream.Stream that yields, as strings, successive lines read from the reader r.
func ReadString ¶
ReadString is a WDTE function with the following signature:
readString s
Returns a reader which reads from the string s.
func Runes ¶
Runes is a WDTE function with the following signature:
runes r
Returns a stream.Stream that yields individual Unicode characters from the reader r as numbers.
TODO: Maybe it makes more sense for them to be yielded as strings with a length of one.
func Scan ¶
Scan is a WDTE function with the following signatures:
scan r sep (scan r) sep scan sep r (scan sep) r
Returns a stream.Stream that yields sections of the reader r split around the separator string sep. For example,
readString 'this--is--an--example' -> scan '--'
will return a stream.Stream that will yield 'this', 'is', 'an', and 'example'.
func Seek ¶
Seek is a WDTE function with the following signatures:
seek s n w (seek w) s n (seek n w) s
Returns s after seeking s to n, with a relative position denoted by w:
If w is greater than 0, it seeks relative to the beginning of s.
If w is equal to 0, it seeks relative to the current location in s.
If w is less than 0, it seeks relative to the end of s.
func String ¶
String is a WDTE function with the following signature:
strings r
Reads the entirety of the reader r and returns the result as a string.
func Words ¶
Words is a WDTE function with the following signature:
words r
Returns a stream.Stream that yields, as strings, successive words read from the reader r.
func Write ¶
Write is a WDTE function with the following signatures:
write w d (write w) d write d w (write d) w
It writes the data d to the writer w in much the same way that Go's fmt.Fprint does. It returns w to allow for easier chaining.
If both arguments are writers, it will consider either the first argument or the outer argument to be w.
func Writeln ¶
Writeln is a WDTE function with the following signatures:
writeln w d (writeln w) d writeln d w (writeln d) w
It writes the data d to the writer w in much the same way that Go's fmt.Fprintln does. It returns w to allow for easier chaining.
If both arguments are writers, it will consider either the first argument or the outer argument to be w.
Types ¶
type Reader ¶
Reader wraps an io.Reader, allowing it to be used as a WDTE function.
Note that using this specific type is not necessary. Any wdte.Func that implements io.Reader is also accepted by the functions in this module.