Files
Ronni Skansing 07c8adaf76 update vendor deps
Signed-off-by: Ronni Skansing <rskansing@gmail.com>
2025-11-06 23:31:08 +01:00
..
2025-11-06 23:31:08 +01:00
2025-11-06 23:31:08 +01:00
2025-11-06 23:31:08 +01:00
2025-11-06 23:31:08 +01:00
2025-11-06 23:31:08 +01:00
2025-11-06 23:31:08 +01:00
2025-11-06 23:31:08 +01:00
2025-11-06 23:31:08 +01:00
2025-11-06 23:31:08 +01:00
2025-11-06 23:31:08 +01:00
2025-11-06 23:31:08 +01:00
2025-11-06 23:31:08 +01:00
2025-11-06 23:31:08 +01:00

GOPHER_ROCKS

iter — Lazy Iterators with Generics for Go

Go Reference Go Report Card Coverage Status Go Ask DeepWiki

iter is a library of lazy iterators for Go. Built on pure functions, no unnecessary allocations, with full generics support and a clean functional style.

Apply transformations like Map, Filter, Take, Fold, Zip directly to sequences — lazily and efficiently.


📦 Installation

go get github.com/enetx/iter

🚀 Example

package main

import (
	"fmt"
	"github.com/enetx/iter"
)

func main() {
	// Extract even numbers and square them:
	s := iter.FromSlice([]int{1, 2, 3, 4, 5})
	s = iter.Filter(s, func(x int) bool { return x%2 == 0 })        // 2, 4
	s = iter.Map(s, func(x int) int { return x * x })              // 4, 16
	out := iter.ToSlice(s)
	fmt.Println(out) // [4 16]
}

Features

  • Lazy sequences — transformations are not applied until iteration begins.
  • Generics-powered — works with any types T, U, structs, etc.
  • Zero-allocation — avoids unnecessary memory allocations.
  • Functional API — each transformation is a pure function: Map, Filter, Take, Skip, StepBy, Flatten, Zip, Enumerate, Fold, Reduce, and many more.
  • Supports pairs, maps, channelsSeq2, FromMap, FromChan, and beyond.

🔬 More Examples

// Simple range with step
r := iter.Iota(1, 10) // 1..9
r = iter.StepBy(r, 3)  // 1, 4, 7
fmt.Println(iter.ToSlice(r)) // → [1 4 7]

// Iterate over a map
m := map[string]int{"a": 1, "b": 2}
s2 := iter.FromMap(m)
iter.ForEach2(s2, func(k string, v int) {
	fmt.Printf("%s → %d\n", k, v)
})

⚖️ License

MIT