tweaks for bulkMap
[bills-tools.git] / seq / README.md
blobca3229a600548d776e0b643281772a739bcae60d
1 SEQ
2 ===
4 Seq provides Sequence, a lazy, concurrent container.  A Sequence is a function which returns a new channel and starts a new goroutine which applies a function to the channel and then closes it.  If you want to enumerate the elements of a Sequence, you can use one of the Sequence methods or you can just call it in the range clause of a for-loop, like this:
6         for el := range seq() {
7                 ...
8         }
10 Sequence supports the following operations:
12 * Seq(f func(c chan Element)) Sequence  
13         returns a new Sequence, a function which returns a new channel and runs a goroutine that applies f to the channel and then closes the channel
14         Note: f must behave properly when the channel is closed from outside.  IsEmpty and First close the channel.
15 * From(el... interface{}) Sequence  
16         returns a new Sequence of el; to make a Sequence from a vector, vec, use this: From(vec...)
17 * Upto(limit int) Sequence  
18         returns a new Sequence of the numbers from 0 to limit
19 * (s Sequence) First() Sequence  
20         returns the first element of s
21 * (s Sequence) Rest() Sequence  
22         returns a new Sequence of the elements of s after the first
23 * IsSeq(el interface{}) bool  
24         returns whether an object is a Sequence
25 * (s Sequence) IsEmpty() bool  
26         returns whether there are any elements in s
27 * (s Sequence) Len() int  
28         returns the length of s
29 * (s Sequence) AddFirst(els... Element) Sequence  
30         returns a new Sequence of els, followed by the elements of s
31 * (s Sequence) AddLast(els... Element) Sequence  
32         returns a new Sequence of the elements of s, followed by els
33 * (s Sequence) Append(s2 Sequence) Sequence  
34         returns a new Sequence of the elements of s, followed by the elements of s2
35 * (s Sequence) Map(f func(el Element) Element) Sequence  
36         returns a new Sequence of the results of f applied to each element of s
37 * (s Sequence) FlatMap(f func(el Element) Sequence) Sequence  
38         returns a new Sequence of the concatenation of the results of f applied to each element of s
39 * (s Sequence) Filter(f func(el Element) bool) Sequence  
40         returns a new Sequence of the elements of s for which f returned true
41 * (s Sequence) Fold(init Element, f func(acc, el Element) Element) Element  
42         apply f to each element of s, along with the return value of the previous evaluation, returns the final value
43 * (s Sequence) Do(f func(el Element))  
44         apply f to each element of s
45 * (s Sequence) Combinations(number int) Sequence  
46         returns a new Sequence containing all combinations of 0 - number elements of s
47 * (s Sequence) Product(sequences Sequence) Sequence  
48         returns the product of the Sequences contained in sequences
49 * (s Sequence) Reify() Sequence  
50         returns a new Sequence containing the elements of s, computed by recursively walking s and all of the sequences it contains.  This is useful to cache s if it is based on expensive computation
51 * (s Sequence) ToArray() []interface{}  
52         returns an array by recursively getting all of the elements from s's channel.  This is like Reify, but any nested Sequences are converted to arrays
53 * (s Sequence) Pretty(names map[Element]string, writer io.Writer)  
54         print s to writer (defaults to Stdout) in a "pretty" way.  Prints Elements which are contained in names are printed as the name
55 * (s Sequence) Prettyln(names map[Element]string, writer io.Writer)  
56         calls Pretty and prints a newline afterwards
57 * Output(c SeqChan, el... interface{})  
58         output all of the elements of s to the channel
59 * (s Sequence) Output(c SeqChan)  
60         output all of the elements of s to the channel