Skip to content

Commit

Permalink
Version 4 API for Go 1.23 (#22)
Browse files Browse the repository at this point in the history
* Remove the iter package. Remove combinatorics ops from slices. Replace maps.Keys and maps.Values with Go 1.23 versions. Adapt to iter.Seq and iter.Seq2 throughout.

* Combine golangci-lint workflow into the go workflow, bump to Go 1.23.

* Update Readme with a compatibility note.

* Remove maps package. Upgrade seqs dependency.

* Upgrade dependency.

* Add set.Collect and set.Of[T].AddSeq.

* Remove set.Of[T].Find, update Readme.

* Remove test for removed set.Of[T].Find method.
  • Loading branch information
bobg authored Aug 16, 2024
1 parent 8b93207 commit 1998b09
Show file tree
Hide file tree
Showing 57 changed files with 657 additions and 3,065 deletions.
20 changes: 16 additions & 4 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,24 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v2
uses: actions/setup-go@v3
with:
go-version: 1.22
go-version: '1.23'

- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: latest

# Optional: golangci-lint command line arguments.
# args: --issues-exit-code=0

# Optional: show only new issues if it's a pull request. The default value is `false`.
# only-new-issues: true

- name: Unit tests
run: go test -v -coverprofile=cover.out ./...
Expand All @@ -27,7 +39,7 @@ jobs:

- name: Modver
if: ${{ github.event_name == 'pull_request' }}
uses: bobg/modver@v2.9.0
uses: bobg/modver@v2.10.0
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
pull_request_url: https://github.com/${{ github.repository }}/pull/${{ github.event.number }}
33 changes: 0 additions & 33 deletions .github/workflows/golangci-lint.yml

This file was deleted.

62 changes: 45 additions & 17 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,56 @@
# 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, and goroutine patterns in Go.

# Compatibility note

This is version 4 of this library,
for the release of Go 1.23.

Earlier versions of this library included a package,
`iter`,
that defined an iterator type over several types of containers,
and functions for operating with iterators.
However, Go 1.23 defines its own, better iterator mechanism
via the new “range over function” language feature,
plus [a new standard-library package](https://pkg.go.dev/iter) also called `iter`.
This version of the go-generics library therefore does away with its `iter` package.
The handy functions that `iter` contained for working with iterators
(`Filter`, `Map`, `FirstN`, and many more)
can now be found in the [github.com/bobg/seqs](https://pkg.go.dev/github.com/bobg/seqs) library,
adapted for Go 1.23 iterators.

(This version of go-generics might have kept `iter` as a drop-in replacement for the standard-library package,
but was unable because the standard library defines two types,
`iter.Seq[K]` and `iter.Seq2[K, V]`,
that go-generics would have had to reference using type aliases;
but Go type aliases [do not yet permit type parameters](https://github.com/golang/go/issues/46477#issuecomment-2101270785).)

Earlier versions of this library included combinatorial operations in the `slices` package.
Those have now been moved to their own library,
[github.com/bobg/combo](https://pkg.go.dev/github.com/bobg/combo).

Earlier versions of this library included a `maps` package,
which was a drop-in replacement for the stdlib `maps`
(added in Go 1.21)
plus a few convenience functions.
With the advent of Go 1.23 iterators,
those few convenience functions are mostly redundant
(and a couple of them − `Keys` and `Values` − conflict with new functions in the standard library),
so `maps` has been removed.

Earlier versions of this library included a `Find` method on the `set.Of[T]` type,
for finding some element in the set that satisfies a given predicate.
This method has been removed in favor of composing operations with functions from [github.com/bobg/seqs](https://pkg.go.dev/github.com/bobg/seqs).
For example, `s.Find(pred)` can now be written as `seqs.First(seqs.Filter(s.All(), pred))`.

# Slices

Expand All @@ -20,9 +62,6 @@ The `slices` package is useful in three ways:
- It includes `Map`, `Filter`, and a few other such functions
for processing slice elements with callbacks.

It also includes combinatorial operations:
`Permutations`, `Combinations`, and `CombinationsWithReplacement`.

The `slices` package is a drop-in replacement
for the `slices` package
added to the Go stdlib
Expand All @@ -32,17 +71,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 Down
13 changes: 6 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
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
golang.org/x/sync v0.7.0
)
require golang.org/x/sync v0.8.0

require github.com/google/go-cmp v0.6.0
require github.com/bobg/seqs v1.0.0

require github.com/bobg/go-generics/v3 v3.7.0 // indirect
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
github.com/bobg/go-generics/v3 v3.7.0 h1:4SJHDWqONTRcA8al6491VW/ys6061bPCcTcI7YnIHPc=
github.com/bobg/go-generics/v3 v3.7.0/go.mod h1:wGlMLQER92clsh3cJoQjbUtUEJ03FoxnGhZjaWhf4fM=
github.com/bobg/seqs v1.0.0 h1:BcBwTAMX9DKkKPx6Q7+uiZwuMw2/Pj3c2HZA9nJBPag=
github.com/bobg/seqs v1.0.0/go.mod h1:icgB+vXIoU6s675tLYVAgcUYry1PkYwgEKvzOuFemOk=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/mattn/go-sqlite3 v1.14.12 h1:TJ1bhYJPV44phC+IMu1u2K/i5RriLTPe+yc68XDJ1Z0=
github.com/mattn/go-sqlite3 v1.14.12/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU=
github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
27 changes: 0 additions & 27 deletions internal/rotate.go

This file was deleted.

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.

22 changes: 0 additions & 22 deletions iter/bench_test.go

This file was deleted.

Loading

0 comments on commit 1998b09

Please sign in to comment.