Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yaa110/goterator
Lazy iterator implementation for Golang
https://github.com/yaa110/goterator
golang golang-module golang-package iterator mapreduce
Last synced: 13 days 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 (about 4 years ago)
- Default Branch: main
- Last Pushed: 2024-07-08T23:40:16.000Z (4 months ago)
- Last Synced: 2024-07-31T20:46:04.673Z (3 months 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 - 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-extra - goterator - 08-12T19:47:57Z|2020-12-02T04:17:39Z| (Generators / Iterators)
README
# Goterator
[![Test and Build](https://github.com/yaa110/goterator/workflows/Test%20and%20Build/badge.svg)](https://github.com/yaa110/goterator/actions?query=workflow%3A"Test+and+Build") [![PkgGoDev](https://pkg.go.dev/badge/github.com/yaa110/goterator)](https://pkg.go.dev/github.com/yaa110/goterator) [![GoDoc](https://img.shields.io/badge/godoc-goterator-blue)](https://godoc.org/github.com/yaa110/goterator) [![Go Report](https://goreportcard.com/badge/github.com/yaa110/goterator)](https://goreportcard.com/report/github.com/yaa110/goterator) [![Coverage](https://gocover.io/_badge/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).