Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New API for Go 1.23 #17

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.22
go-version: 1.23

- name: Unit tests
run: go test -v -coverprofile=cover.out ./...
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
steps:
- uses: actions/setup-go@v3
with:
go-version: '1.22'
go-version: '1.23'
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
Expand Down
32 changes: 11 additions & 21 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Go-generics - Generic slice, map, set, iterator, and goroutine utilities for Go

[![Go Reference](https://pkg.go.dev/badge/github.com/bobg/go-generics/v3.svg)](https://pkg.go.dev/github.com/bobg/go-generics/v3)
[![Go Report Card](https://goreportcard.com/badge/github.com/bobg/go-generics/v3)](https://goreportcard.com/report/github.com/bobg/go-generics/v3)
[![Go Reference](https://pkg.go.dev/badge/github.com/bobg/go-generics/v4.svg)](https://pkg.go.dev/github.com/bobg/go-generics/v4)
[![Go Report Card](https://goreportcard.com/badge/github.com/bobg/go-generics/v4)](https://goreportcard.com/report/github.com/bobg/go-generics/v4)
[![Tests](https://github.com/bobg/go-generics/actions/workflows/go.yml/badge.svg)](https://github.com/bobg/go-generics/actions/workflows/go.yml)
[![Coverage Status](https://coveralls.io/repos/github/bobg/go-generics/badge.svg?branch=master)](https://coveralls.io/github/bobg/go-generics?branch=master)
[![Mentioned in Awesome Go](https://awesome.re/mentioned-badge.svg)](https://github.com/avelino/awesome-go)

This is go-generics,
a collection of typesafe generic utilities
for slices, maps, sets, iterators, and goroutine patterns in Go.
for slices, sets, iterators, and goroutine patterns in Go.

# Slices

Expand All @@ -32,17 +32,6 @@ this version of `slices`
allows the index value passed to `Insert`, `Delete`, and `Replace`
to be negative for counting backward from the end of the slice.

# Maps

The `maps` package has a few convenience functions
for duplicating, inverting, constructing, and iterating over maps,
as well as for testing their equality.

The `maps` package is a drop-in replacement
for the `maps` package
added to the Go stdlib
in [Go 1.21](https://go.dev/doc/go1.21#maps).

# Set

The `set` package implements the usual collection of functions for sets:
Expand All @@ -51,14 +40,15 @@ as well as member functions for adding and removing items,
checking for the presence of items,
and iterating over items.

# Iter
# Seqs

The `iter` package implements efficient, typesafe iterators
that can convert to and from Go slices, maps, and channels,
and produce iterators over the values from function calls and goroutines.
There is also an iterator over the results of a SQL query;
the usual collection of functions on iterators
(`Filter`, `Map`, `Concat`, `Accum`, etc.).
The `seqs` package provides ways to create and work with Go 1.23 “range-over-func” iterators.
It includes the usual collection of functions on iterators
(`Filter`, `Map`, `Concat`, `Accum`, etc.),
plus adapters for getting iterators over channels and strings,
iterating over the results of a SQL query,
iterating over lines of text,
and more.

# Parallel

Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/bobg/go-generics/v3
module github.com/bobg/go-generics/v4

go 1.22
go 1.23

require (
github.com/mattn/go-sqlite3 v1.14.22
Expand Down
2 changes: 1 addition & 1 deletion internal/rotate.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ package internal
// in order to resolve an import cycle
// that would otherwise exist
// between iter and slices.
func RotateSlice[S ~[]T, T any](s S, n int) {
func RotateSlice[T any, S ~[]T](s S, n int) {
if n < 0 {
// Convert left-rotation to right-rotation.
n = -n
Expand Down
61 changes: 61 additions & 0 deletions internal/rotate_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package internal

import (
"fmt"
"slices"
"testing"
)

func TestRotateSlice(t *testing.T) {
cases := []struct {
slice []int
rot int
want []int
}{{
slice: []int{1, 2, 3},
rot: 0,
want: []int{1, 2, 3},
}, {
slice: []int{1, 2, 3},
rot: 1,
want: []int{3, 1, 2},
}, {
slice: []int{1, 2, 3},
rot: 2,
want: []int{2, 3, 1},
}, {
slice: []int{1, 2, 3},
rot: 3,
want: []int{1, 2, 3},
}, {
slice: []int{1, 2, 3},
rot: 4,
want: []int{3, 1, 2},
}, {
slice: []int{1, 2, 3},
rot: -1,
want: []int{2, 3, 1},
}, {
slice: []int{1, 2, 3},
rot: -2,
want: []int{3, 1, 2},
}, {
slice: []int{1, 2, 3},
rot: -3,
want: []int{1, 2, 3},
}, {
slice: []int{1, 2, 3},
rot: -4,
want: []int{2, 3, 1},
}}

for i, tc := range cases {
t.Run(fmt.Sprintf("case_%02d", i+1), func(t *testing.T) {
slice := append([]int(nil), tc.slice...)
RotateSlice(slice, tc.rot)
if !slices.Equal(slice, tc.want) {
t.Fatalf("got %v, want %v", slice, tc.want)
}
})
}
}
66 changes: 0 additions & 66 deletions iter/accum.go

This file was deleted.

18 changes: 0 additions & 18 deletions iter/accum_test.go

This file was deleted.

148 changes: 0 additions & 148 deletions iter/chan.go

This file was deleted.

Loading
Loading