Documentation ¶
Overview ¶
builders package provide utilities to generate iterators
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Channel ¶
Channel allows you to convert a channel into an interator
Example ¶
package main import ( "fmt" "slices" "github.com/4strodev/iterago/builders" "github.com/4strodev/iterago/transformers" ) func main() { channel := make(chan int) go func() { for _, v := range builders.Range(0, 10, 1) { channel <- v } close(channel) }() iterator := builders.Channel(channel) evenIterator := transformers.Filter(iterator, func(i int, v int) bool { return v%2 == 0 }) evenValues := slices.Collect(transformers.Values(evenIterator)) fmt.Println(evenValues) }
Output: [0 2 4 6 8]
func Range ¶
Range returns an iterator with the specified boundaries it starts the iterator with an iteration value that is equal to start and ends when the iteration value is equal to end. After each iteration the next value is calculated summing jump to the current value. If the parameters are put correctly an infinite or reverse iterator can be created.
Example ¶
package main import ( "fmt" "slices" "github.com/4strodev/iterago/builders" "github.com/4strodev/iterago/transformers" ) func main() { rangeIterator := builders.Range(0, 10, 2) slice := slices.Collect(transformers.Values(rangeIterator)) fmt.Println(slice) }
Output: [0 2 4 6 8]
Example (Infinite) ¶
package main import ( "fmt" "github.com/4strodev/iterago/builders" ) func main() { // Infinite loop for _, v := range builders.Range(0, -1, 1) { if v == 10 { break } fmt.Println(v) } }
Output: 0 1 2 3 4 5 6 7 8 9
Example (Reverse) ¶
package main import ( "fmt" "slices" "github.com/4strodev/iterago/builders" "github.com/4strodev/iterago/transformers" ) func main() { rangeIterator := builders.Range(10, 0, -2) slice := slices.Collect(transformers.Values(rangeIterator)) fmt.Println(slice) }
Output: [10 8 6 4 2]
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.