Documentation ¶
Overview ¶
Package flow is a helper library around "iter.Seq" types.
The library is intend to provide the lacking wheels from standard and/or "x/exp/xiter" library.
For example, "Empty" and "Pack" is provided to build a sequence of zero and one item, "Any" and "All" boolean short-circuit is also provided. But "Map", "Filter" and "Reduce" is not provided since that is planned to be in "x/exp/xiter". Also transformation from/to slice/map is in the standard library "slices" and "maps".
All function Xxx comes with a Xxx2 version to address the usage between "iter.Seq" and "iter.Seq2", if reasonable.
Function with immediate transformation, e.g. key, is not provided, since that users can already achieve with another "Map" operation.
Wish someday we can use tuple as primitive generic type, so we don't have to write these Xxx2 stuffs.
Example ¶
type Node struct { val int left *Node right *Node } var traverse func(node *Node) iter.Seq[int] traverse = func(node *Node) iter.Seq[int] { // Empty is useful as base case during recursive generator chaining. if node == nil { return Empty[int]() } // Pack is useful to promote a single value into a iterable for chaining. return Chain( traverse(node.left), Pack(node.val), traverse(node.right), ) } root := &Node{ val: 3, left: &Node{ val: 2, left: &Node{val: 1}, }, right: &Node{ val: 5, left: &Node{val: 4}, }, } var results []int for val := range traverse(root) { results = append(results, val) if val == 4 { break } } fmt.Printf("%v\n", results)
Output: [1 2 3 4]
Index ¶
- func All(conditions iter.Seq[bool]) bool
- func Any(conditions iter.Seq[bool]) bool
- func Backward(begin int, end int) iter.Seq[int]
- func Chain[V any](sequences ...iter.Seq[V]) iter.Seq[V]
- func Chain2[K, V any](sequences ...iter.Seq2[K, V]) iter.Seq2[K, V]
- func Drop[V any](sequence iter.Seq[V], count int) iter.Seq[V]
- func Drop2[K, V any](sequence iter.Seq2[K, V], count int) iter.Seq2[K, V]
- func Empty[V any]() iter.Seq[V]
- func Empty2[K, V any]() iter.Seq2[K, V]
- func Forward(begin int, end int) iter.Seq[int]
- func Pack[V any](v V) iter.Seq[V]
- func Pack2[K, V any](k K, v V) iter.Seq2[K, V]
- func Since(start int) iter.Seq[int]
- func Take[V any](sequence iter.Seq[V], count int) iter.Seq[V]
- func Take2[K, V any](sequence iter.Seq2[K, V], count int) iter.Seq2[K, V]
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Chain ¶
Chain chains multiple sequences together.
Only for demonstration, consider "x/exp/xiter.Concat" once the official one is available.
Types ¶
This section is empty.