go2linq is Go implementation of .NET's LINQ to Objects. (See also: Language Integrated Query, LINQ, Enumerable Class.)
go2linq is inspired by Jon Skeet's Edulinq series.
Since go2linq uses generics it requires at least Go 1.18. Use go1.18rc1 or gotip to experiment with go2linq.
Examples of go2linq usage are in the Example...
functions in test files
(see Examples).
//go:build go1.18
package main
import (
"fmt"
"github.com/solsw/go2linq/v2"
)
func main() {
filter := go2linq.WhereMust(
go2linq.NewEnSlice(1, 2, 3, 4, 5, 6, 7, 8),
func(i int) bool { return i > 6 || i%2 == 0 },
)
squares := go2linq.SelectMust(
filter,
func(i int) string { return fmt.Sprintf("%d: %d", i, i*i) },
)
enr := squares.GetEnumerator()
for enr.MoveNext() {
square := enr.Current()
fmt.Println(square)
}
}
The previous code prints the following:
2: 4
4: 16
6: 36
7: 49
8: 64