Skip to content
/ go2linq Public

Generic Go implementation of .NET's LINQ to Objects.

License

Notifications You must be signed in to change notification settings

solsw/go2linq

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go2linq

Go Reference

go2linq v4 is Go implementation of .NET's LINQ to Objects. (See also: Language Integrated Query, LINQ, Enumerable Class.)

go2linq v4 is based on iter.Seq, so it requires setting GOEXPERIMENT=rangefunc when executing go commands.


Installation

go get github.com/solsw/go2linq/v4

Examples

Examples of go2linq usage are in the Example... functions in test files (see Examples).

Quick and easy example:

package main

import (
	"fmt"

	"github.com/solsw/go2linq/v4"
)

func main() {
	filter, _ := go2linq.Where(
		go2linq.VarAll(1, 2, 3, 4, 5, 6, 7, 8),
		func(i int) bool { return i > 6 || i%2 == 0 },
	)
	squares, _ := go2linq.Select(
		filter,
		func(i int) string { return fmt.Sprintf("%d: %d", i, i*i) },
	)
	for square := range squares {
		fmt.Println(square)
	}
}

The previous code outputs the following:

2: 4
4: 16
6: 36
7: 49
8: 64