Popularity
1.7
Declining
Activity
0.0
Stable
16
3
4

Programming language: Go
License: MIT License
Tags: Data Structures    
Latest version: v0.3.0

goterator alternatives and similar packages

Based on the "Data Structures" category.
Alternatively, view goterator alternatives based on common mentions on social networks and blogs.

Do you think we are missing an alternative of goterator or a related project?

Add another 'Data Structures' Package

README

Goterator

Test and Build PkgGoDev GoDoc Go Report Coverage

Iterator implementation for Golang to provide map and reduce functionalities.

Package

import (
    "github.com/yaa110/goterator"
    "github.com/yaa110/goterator/generator"
)

Getting Started

  • Create a generator from slices
words := []interface{}{"an", "example", "of", "goterator"}

gen := generator.NewSlice(words)
  • Create a generator from channels
chn := make(chan interface{}, 4)
chn <- "an"
chn <- "example"
chn <- "of"
chn <- "goterator"
close(chn)

gen := generator.NewChannel(chn)
  • Create custom generators
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
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.