chore: teach set module about iter.Seq (#6676)

- Add a new `Seq` function to the `Set` type, this returns an iterator over the values.
- Convert some users of the `Values` method to allow for more optimal code.

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/6676
Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org>
Co-authored-by: Gusted <postmaster@gusted.xyz>
Co-committed-by: Gusted <postmaster@gusted.xyz>
This commit is contained in:
Gusted 2025-01-24 16:45:46 +00:00 committed by Earl Warren
parent 46e60ce966
commit 443f7d59f9
9 changed files with 38 additions and 28 deletions

View file

@ -4,6 +4,7 @@
package container
import (
"slices"
"testing"
"github.com/stretchr/testify/assert"
@ -29,6 +30,14 @@ func TestSet(t *testing.T) {
assert.True(t, s.Contains("key4"))
assert.True(t, s.Contains("key5"))
values := s.Values()
called := 0
for value := range s.Seq() {
called++
assert.True(t, slices.Contains(values, value))
}
assert.EqualValues(t, len(values), called)
s = SetOf("key6", "key7")
assert.False(t, s.Contains("key1"))
assert.True(t, s.Contains("key6"))