Documentation ¶
Overview ¶
Package stream provides WDTE functions for manipulating streams of data.
Index ¶
- Variables
- func All(frame wdte.Frame, args ...wdte.Func) wdte.Func
- func Any(frame wdte.Frame, args ...wdte.Func) wdte.Func
- func Collect(frame wdte.Frame, args ...wdte.Func) wdte.Func
- func Concat(frame wdte.Frame, args ...wdte.Func) wdte.Func
- func Drain(frame wdte.Frame, args ...wdte.Func) wdte.Func
- func Enumerate(frame wdte.Frame, args ...wdte.Func) wdte.Func
- func Filter(frame wdte.Frame, args ...wdte.Func) wdte.Func
- func FlatMap(frame wdte.Frame, args ...wdte.Func) wdte.Func
- func Map(frame wdte.Frame, args ...wdte.Func) wdte.Func
- func New(frame wdte.Frame, args ...wdte.Func) wdte.Func
- func Range(frame wdte.Frame, args ...wdte.Func) wdte.Func
- func Reduce(frame wdte.Frame, args ...wdte.Func) wdte.Func
- type NextFunc
- type Stream
Constants ¶
This section is empty.
Variables ¶
var Scope = wdte.S().Map(map[wdte.ID]wdte.Func{ "new": wdte.GoFunc(New), "range": wdte.GoFunc(Range), "concat": wdte.GoFunc(Concat), "map": wdte.GoFunc(Map), "filter": wdte.GoFunc(Filter), "flatMap": wdte.GoFunc(FlatMap), "enumerate": wdte.GoFunc(Enumerate), "collect": wdte.GoFunc(Collect), "drain": wdte.GoFunc(Drain), "reduce": wdte.GoFunc(Reduce), "any": wdte.GoFunc(Any), "all": wdte.GoFunc(All), })
Scope is a scope containing the functions in this package.
Functions ¶
func All ¶
All is a WDTE function with the following signatures:
all s f (all f) s
It iterates over the Stream s, passing each yielded element to f in turn. If all of those calls return true, then the entire function returns true. Otherwise it returns false. It is short-circuiting.
func Any ¶
Any is a WDTE function with the following signatures:
any s f (any f) s
It iterates over the Stream s, passing each yielded element to f in turn. If any of those calls returns true, then the entire function returns true. Otherwise it returns false. It is short-circuiting.
func Collect ¶
Collect is a WDTE function with the following signature:
collect s
Iterates through the Stream s, collecting the yielded elements into an array. When the Stream ends, it returns the collected array.
func Concat ¶
Concat is a WDTE function with the following signatures:
concat s ... (concat s) ...
It returns a new Stream that yields the values of all of its argument Streams in the order that they were given.
func Drain ¶
Drain is a WDTE function with the following signature:
drain s
Drain is the same as Collect, but it simply discards elements as they are yielded by the Stream, returning the empty Stream when it's done. The main purpose of this function is to allow Map to be used as a foreach-style loop without the allocation that Collect performs.
func Enumerate ¶
Enumerate is a WDTE function with the following signature:
enumerate s
It returns a Stream which yields values of the form [i; v] where i is the zero-based index of the element v that was yielded by the Stream s.
func Filter ¶
Filter is a WDTE function with the following signature:
(filter f) s
It returns a Stream which yields only those values yielded by the Stream s that (f value) results in true for.
func FlatMap ¶
FlatMap is a WDTE function with the following signature:
(flatMap f) s
It's identical to Map with one caveat: If a call to f yields a Stream, the elements of that Stream are yielded in turn before continuing the iteration of s. In other words,
range 3 -> flatMap (new 0 1) -> collect
returns
[0; 1; 0; 1; 0; 1]
func Map ¶
Map is a WDTE function with the following signature:
(map f) s
It returns a Stream which calls f on each element yielded by the Stream s, yielding the return values of f in their place.
func New ¶
New is a WDTE function with the following signature:
new ...
It returns a Stream that iterates over its arguments.
func Range ¶
Range is a WDTE function with the following signatures:
range end range start end range start end step
It returns a new Stream which iterates from start to end, stepping by step each time. In other words, it's similar to the following pseudo Go code
for i := start; i < end; i += step { yield i }
but with the difference that if step is negative, then the loop condition is inverted.
If start is not specified, it is assumed to be 0. If step is not specified it is assumed to be 1 if start is greater than or equal to end, and -1 if start is less then end.
func Reduce ¶
Reduce is a WDTE function with the following signatures:
reduce s i r (reduce r) s i (reduce i r) s
Reduce performs a reduction on the Stream s, resulting in a single value, which is returned. i is the initial value for the reduction, and r is the reducer. r is expected to have the following signature:
r acc n
r is passed the accumulated value as acc, starting with i, and the latest value yielded by the Stream as n. Whatever value r returns is used as the next value of acc until the Stream is empty, at which point the last value of acc is returned. For example,
range 5 -> reduce 0 +
returns a summation of the range [0,5).