more happy formatting :(
[bills-tools.git] / seq / README.md
blob2a8893454b02fb449e4e701aa130165ad82f0935
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 * From(el... interface{}) Sequence
16                 returns a new Sequence of el
17 * Upto(limit int) Sequence
19                 returns a new Sequence of the numbers from 0 to limit
20 * (s Sequence) First() Sequence
22                 returns the first element of s
23 * (s Sequence) Rest() Sequence
25                 returns a new Sequence of the elements of s after the first
26 * IsSeq(el interface{}) bool
28                 returns whether an object is a Sequence
29 * (s Sequence) IsEmpty() bool
31                 returns whether there are any elements in s
32 * (s Sequence) Len() int
34                 returns the length of s
35 * (s Sequence) AddFirst(els... Element) Sequence
37                 returns a new Sequence of els, followed by the elements of s
38 * (s Sequence) AddLast(els... Element) Sequence
40                 returns a new Sequence of the elements of s, followed by els
41 * (s Sequence) Append(s2 Sequence) Sequence
43                 returns a new Sequence of the elements of s, followed by the elements of s2
44 * (s Sequence) Map(f func(el Element) Element) Sequence
46                 returns a new Sequence of the results of f applied to each element of s
47 * (s Sequence) FlatMap(f func(el Element) Sequence) Sequence
49                 returns a new Sequence of the concatenation of the results of f applied to each element of s
50 * (s Sequence) Filter(f func(el Element) bool) Sequence
52                 returns a new Sequence of the elements of s for which f returned true
53 * (s Sequence) Fold(init Element, f func(acc, el Element) Element) Element
55                 apply f to each element of s, along with the return value of the previous evaluation, returns the final value
56 * (s Sequence) Do(f func(el Element))
58                 apply f to each element of s
59 * (s Sequence) Combinations(number int) Sequence
61                 returns a new Sequence containing all combinations of 0 - number elements of s
62 * (s Sequence) Product(sequences Sequence) Sequence
64                 returns the product of the Sequences contained in sequences
65 * (s Sequence) Reify() Sequence
67                 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
68 * (s Sequence) Pretty(names map[Element]string, writer io.Writer)
70                 print s to writer (defaults to Stdout) in a "pretty" way.  Prints Elements which are contained in names are printed as the name
71 * (s Sequence) Prettyln(names map[Element]string, writer io.Writer)
73                 calls Pretty and prints a newline afterwards
74 * Output(c SeqChan, el... interface{})
76                 output all of the elements of s to the channel
77 * (s Sequence) Output(c SeqChan)
79                 output all of the elements of s to the channel
80 * Bleed(c SeqChan)
82                 read the remaining elements of c