Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Collect ¶
Collect consumes an iterator and returns a slice of all items yielded.
Example ¶
package main
import (
"fmt"
"github.com/BooleanCat/go-functional/v2/iter"
)
func main() {
fmt.Println(iter.Collect(iter.Lift([]int{1, 2})))
}
Output: [1 2]
Example (Method) ¶
package main
import (
"fmt"
"github.com/BooleanCat/go-functional/v2/iter"
)
func main() {
fmt.Println(iter.Lift([]int{1, 2}).Collect())
}
Output: [1 2]
Types ¶
type Iterator ¶
Iterator is a wrapper around the iter.Seq type that allowed for method chaining of iterators found in this package.
func Count ¶
Count yields an infinite sequence of integers, starting from 0.
Example ¶
package main
import (
"fmt"
"github.com/BooleanCat/go-functional/v2/iter"
)
func main() {
for i := range iter.Count().Take(3) {
fmt.Println(i)
}
}
Output: 0 1 2
func Lift ¶
Lift yields all items in the provided slice.
Example ¶
package main
import (
"fmt"
"github.com/BooleanCat/go-functional/v2/iter"
)
func main() {
for i := range iter.Lift([]int{1, 2}) {
fmt.Println(i)
}
}
Output: 1 2
func Take ¶
Take limits the number of elements yielded by a delegate iterator to a maximum limit.
Example ¶
package main
import (
"fmt"
"github.com/BooleanCat/go-functional/v2/iter"
)
func main() {
for i := range iter.Take(iter.Lift([]int{1, 2, 3}), 2) {
fmt.Println(i)
}
}
Output: 1 2
Example (Method) ¶
package main
import (
"fmt"
"github.com/BooleanCat/go-functional/v2/iter"
)
func main() {
for i := range iter.Lift([]int{1, 2, 3}).Take(2) {
fmt.Println(i)
}
}
Output: 1 2
Click to show internal directories.
Click to hide internal directories.