Skip to content

Commit

Permalink
Merge remote branch 'origin/master' into release
Browse files Browse the repository at this point in the history
* origin/master:
  documented source file
  • Loading branch information
zot committed Nov 9, 2010
2 parents acd0c0d + 9dcc97c commit 8a54366
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 81 deletions.
60 changes: 6 additions & 54 deletions seq/README.md
@@ -1,60 +1,12 @@
SEQ
===

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:
The seq package provides functional sequences with the Seq interface. Seq provides two concrete implementations: SequentialSeq and ConcurrentSeq. SequentialSeq is like vector, and ConcurrentSeq is like a vector that calculates its elements in the background, which can be used for lazy sequences or for some types of parallel computation.

for el := range seq() {
...
}
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:

Sequence supports the following operations:
Do(seq, func(el El){
...
})

* Seq(f func(c chan Element)) Sequence
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
Note: f must behave properly when the channel is closed from outside. IsEmpty and First close the channel.
* From(el... interface{}) Sequence
returns a new Sequence of el; to make a Sequence from a vector, vec, use this: From(vec...)
* Upto(limit int) Sequence
returns a new Sequence of the numbers from 0 to limit
* (s Sequence) First() Sequence
returns the first element of s
* (s Sequence) Rest() Sequence
returns a new Sequence of the elements of s after the first
* IsSeq(el interface{}) bool
returns whether an object is a Sequence
* (s Sequence) IsEmpty() bool
returns whether there are any elements in s
* (s Sequence) Len() int
returns the length of s
* (s Sequence) AddFirst(els... Element) Sequence
returns a new Sequence of els, followed by the elements of s
* (s Sequence) AddLast(els... Element) Sequence
returns a new Sequence of the elements of s, followed by els
* (s Sequence) Append(s2 Sequence) Sequence
returns a new Sequence of the elements of s, followed by the elements of s2
* (s Sequence) Map(f func(el Element) Element) Sequence
returns a new Sequence of the results of f applied to each element of s
* (s Sequence) FlatMap(f func(el Element) Sequence) Sequence
returns a new Sequence of the concatenation of the results of f applied to each element of s
* (s Sequence) Filter(f func(el Element) bool) Sequence
returns a new Sequence of the elements of s for which f returned true
* (s Sequence) Fold(init Element, f func(acc, el Element) Element) Element
apply f to each element of s, along with the return value of the previous evaluation, returns the final value
* (s Sequence) Do(f func(el Element))
apply f to each element of s
* (s Sequence) Combinations(number int) Sequence
returns a new Sequence containing all combinations of 0 - number elements of s
* (s Sequence) Product(sequences Sequence) Sequence
returns the product of the Sequences contained in sequences
* (s Sequence) Reify() Sequence
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
* (s Sequence) ToArray() []interface{}
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
* (s Sequence) Pretty(names map[Element]string, writer io.Writer)
print s to writer (defaults to Stdout) in a "pretty" way. Prints Elements which are contained in names are printed as the name
* (s Sequence) Prettyln(names map[Element]string, writer io.Writer)
calls Pretty and prints a newline afterwards
* Output(c SeqChan, el... interface{})
output all of the elements of s to the channel
* (s Sequence) Output(c SeqChan)
output all of the elements of s to the channel
The functionality is mainly accessible through functions, rather than methods, although there is partial method support. The methods are mainly there to support the functions. Please see the documentation for more information.

0 comments on commit 8a54366

Please sign in to comment.