# README
Iter
Iterator and utilities.
Some inspiration from ReactiveX.
Examples
Iterating
Iterate over an iterator
package main
import (
"fmt"
"github.com/EliCDavis/iter"
)
func main() {
arr := iter.Array([]int{1, 2, 3, 4, 5})
sum := 0
for {
val, err := arr.Next()
if err != nil {
break
}
sum += val
}
// Prints: 15
fmt.Println(sum)
}
Mapping
Map an iterator of one type to an iterator of a different type.
package main
import (
"fmt"
"strconv"
"github.com/EliCDavis/iter"
"github.com/EliCDavis/iter/iterops"
)
func main() {
arr := iter.Array([]string{"1", "2", "3", "4", "5"})
mapper := iterops.Map[string, int](&arr, func(s string) int {
parsed, err := strconv.Atoi(s)
if err != nil {
panic(err)
}
return parsed
})
// Prints: [1 2 3 4 5]
fmt.Println(iter.ReadFull(mapper))
}
Range
Range is a bound iterator that emits values incrementally starting from 0 and increasing to n-1, with n being the value specified in the Range constructor.
package main
import (
"fmt"
"github.com/EliCDavis/iter"
)
func main() {
// Prints: 10 (0 + 1 + 2 + 3 + 4)
fmt.Println(iter.Sum(iter.Range(5)))
}
# Packages
No description provided by the author
# Variables
Error to indicate the iterator is at the end of it's sequence.
Error to indicate the value passed into the Range iterator is invalid.
Error to indicate that the bound iterator is attempting to have an element accessed that is out of it's bounds.
# Structs
No description provided by the author
No description provided by the author
# Interfaces
No description provided by the author
No description provided by the author
No description provided by the author