It and New Go Iterators
As Go 1.23 reaches Release Candidate
status the previous
rangefunc experiment has been stabilized and
iterators are a part of a
compiler and a standard library.
- The
iterpackage provides common type definitions. - The
slicespackage has several functions that work with iterators - The
mapspackage has several functions that work withiter.Seq2and maps
Installing a release candidate of Go
Since Go 1.23 has not been released yet, you need to install a release candidate. With
recent changes and a GOTOOLCHAIN support, this is easier than ever.
# Given an installed go compiler
$ go version
go version go1.22.5 linux/amd64
# Get the release candidate and set it in a go.mod
$ go get go@1.23rc2 toolchain@1.23rc2
# And make it a default
$ GOTOOLCHAIN="go1.23rc2" go version
go version go1.23rc2 linux/amd64
$ cat go.mod
module github.com/gomoni/it
go 1.23rc2
A simple export GOTOOLCHAIN=go1.23rc2 is all that is needed to make go
and a language server and other tools to work with a new release. See the Forward
Compatibility and Toolchain Management in Go
1.21 from the Go Blog for more details.
it v0.1.0
Changes to a standard library made most of
github.com/gomoni/it obsolete. And it is never
a good idea for third-party packages to compete and duplicate it.
Surprisingly neither Filter, neither Map helpers got there, making
it@v0.1.0 a perfect place
for them. To be closer to the standard library these helpers exists in a
respective subpackage
The it itself provides a Chain and Mappable structs providing a
chainable API for a helper functions.
package main
import (
"fmt"
"slices"
"github.com/gomoni/it"
)
func main() {
n := []string{"aa", "aaa", "aaaaaaa", "a"}
ch := it.NewMapable[string, int](slices.Values(n))
slice := ch.
Filter(func(s string) bool { return len(s) >= 2 }).
Map(func(s string) int { return len(s) }).
Collect()
fmt.Println(slice)
}Request pkg.go.dev upgrade
As soon as the new release v0.1.0 was tagged, pkg.go.dev showed obsolete information. It turns out that there is an easy process for requesting an update.
Let me use a hypothetical v0.1.109 release, to make a link work even for the future releases.
- Go to the version which does not exists yet (https://pkg.go.dev/github.com/gomoni/it@v0.1.109)
- Click on a button that says Request “github.com.../it@v0.1.109”
- Profit!