Skip to content

Commit

Permalink
Support iter.Seq2 for *FieldValue (#625)
Browse files Browse the repository at this point in the history
* Support iter.Seq2 for *FieldValue

* Add go 1.23 to test matrix

* Rename method name and fix test
  • Loading branch information
tamayika authored Aug 30, 2024
1 parent 9a347d7 commit c7264b6
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
fail-fast: false
matrix:
module: ${{fromJson(needs.prepare-matrix.outputs.matrix)}}
go-version: ['1.21.0', '1.22.0']
go-version: ['1.21.0', '1.22.0', '1.23.0']
steps:
- name: Checkout code
uses: actions/checkout@v4
Expand Down
26 changes: 26 additions & 0 deletions internal/cmds/iter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//go:build go1.23

package cmds

import "iter"

func (c HmsetFieldValue) FieldValueIter(seq iter.Seq2[string, string]) HmsetFieldValue {
for field, value := range seq {
c.cs.s = append(c.cs.s, field, value)
}
return c
}

func (c HsetFieldValue) FieldValueIter(seq iter.Seq2[string, string]) HsetFieldValue {
for field, value := range seq {
c.cs.s = append(c.cs.s, field, value)
}
return c
}

func (c XaddFieldValue) FieldValueIter(seq iter.Seq2[string, string]) XaddFieldValue {
for field, value := range seq {
c.cs.s = append(c.cs.s, field, value)
}
return c
}
19 changes: 19 additions & 0 deletions internal/cmds/iter_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//go:build go1.23

package cmds

import (
"maps"
"testing"
)

func iter0(s Builder) {
s.Hmset().Key("1").FieldValue().FieldValueIter(maps.All(map[string]string{"1": "1"})).Build()
s.Hset().Key("1").FieldValue().FieldValueIter(maps.All(map[string]string{"1": "1"})).Build()
s.Xadd().Key("1").Id("*").FieldValue().FieldValueIter(maps.All(map[string]string{"1": "1"})).Build()
}

func TestIter(t *testing.T) {
var s = NewBuilder(InitSlot)
t.Run("0", func(t *testing.T) { iter0(s) })
}

0 comments on commit c7264b6

Please sign in to comment.