https://github.com/yaa110/goterator
Lazy iterator implementation for Golang
https://github.com/yaa110/goterator
golang golang-module golang-package iterator mapreduce
Last synced: 7 months ago
JSON representation
Lazy iterator implementation for Golang
- Host: GitHub
- URL: https://github.com/yaa110/goterator
- Owner: yaa110
- License: mit
- Created: 2020-08-12T19:47:57.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2024-07-08T23:40:16.000Z (over 1 year ago)
- Last Synced: 2024-07-31T20:46:04.673Z (over 1 year ago)
- Topics: golang, golang-module, golang-package, iterator, mapreduce
- Language: Go
- Homepage: https://godoc.org/github.com/yaa110/goterator
- Size: 19.5 KB
- Stars: 16
- Watchers: 3
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-go-cn - goterator
- awesome-go - goterator - Iterator implementation to provide map and reduce functionalities. (Data Structures and Algorithms / Iterators)
- awesome-go - goterator - Iterator implementation to provide map and reduce functionalities. (Data Structures and Algorithms / Iterators)
- fucking-awesome-go - goterator - Iterator implementation to provide map and reduce functionalities. (Data Structures and Algorithms / Iterators)
- awesome-go-plus - goterator - Iterator implementation to provide map and reduce functionalities.  (Data Structures and Algorithms / Iterators)
- awesome-go - goterator - Iterator implementation to provide map and reduce functionalities. (Data Structures and Algorithms / Iterators)
- awesome-go-with-stars - goterator - Iterator implementation to provide map and reduce functionalities. (Data Structures and Algorithms / Iterators)
- awesome-go - goterator - Iterator implementation to provide map and reduce functionalities. (Data Structures and Algorithms / Iterators)
- awesome-go-cn - goterator
- awesome-Char - goterator - Iterator implementation to provide map and reduce functionalities. (Data Structures / Advanced Console UIs)
- awesome-go-cn - goterator
- awesome-go - goterator - Iterator implementation to provide map and reduce functionalities. (Data Structures and Algorithms / Iterators)
- awesome-go-extra - goterator - 08-12T19:47:57Z|2020-12-02T04:17:39Z| (Generators / Iterators)
README
# Goterator
[](https://github.com/yaa110/goterator/actions?query=workflow%3A"Test+and+Build") [](https://pkg.go.dev/github.com/yaa110/goterator) [](https://godoc.org/github.com/yaa110/goterator) [](https://goreportcard.com/report/github.com/yaa110/goterator) [](https://gocover.io/github.com/yaa110/goterator)
Iterator implementation for Golang to provide map and reduce functionalities.
## Package
```go
import (
"github.com/yaa110/goterator"
"github.com/yaa110/goterator/generator"
)
```
## Getting Started
- Create a generator from slices
```go
words := []interface{}{"an", "example", "of", "goterator"}
gen := generator.NewSlice(words)
```
- Create a generator from channels
```go
chn := make(chan interface{}, 4)
chn <- "an"
chn <- "example"
chn <- "of"
chn <- "goterator"
close(chn)
gen := generator.NewChannel(chn)
```
- Create custom generators
```go
type TestGenerator struct {
words []string
i int
value string
}
func (g *TestGenerator) Next() bool {
if g.i == len(g.words) {
return false
}
g.value = g.words[g.i]
g.i++
return true
}
func (g *TestGenerator) Value() interface{} {
return g.value
}
gen := &TestGenerator{
words: []string{"an", "example", "of", "goterator"},
i: 0,
value: "",
}
```
- Iterate over generators
```go
lengths := goterator.New(gen).Map(func(word interface{}) interface{} {
return len(word.(string))
}).Collect()
assert.Equal([]interface{}{2, 7, 2, 9}, lengths)
```
Please for more information about mappers and reducers (consumers) check the [documentation](https://godoc.org/github.com/yaa110/goterator).