File tree Expand file tree Collapse file tree 2 files changed +4
-15
lines changed Expand file tree Collapse file tree 2 files changed +4
-15
lines changed Original file line number Diff line number Diff line change 9
9
"github.com/lib/pq"
10
10
"github.com/pkg/errors"
11
11
"golang.org/x/exp/utf8string"
12
+ "iter"
12
13
"net"
13
14
"os"
14
15
"path/filepath"
@@ -170,11 +171,7 @@ func PrintErrorThenExit(err error, exitCode int) {
170
171
//
171
172
// This function returns a func yielding key-value-pairs from a given map in the order of their keys, if their type
172
173
// is cmp.Ordered.
173
- //
174
- // Please note that currently - being at Go 1.22 - rangefuncs are still an experimental feature and cannot be directly
175
- // used unless compiled with `GOEXPERIMENT=rangefunc`. However, they can still be invoked normally.
176
- // https://go.dev/wiki/RangefuncExperiment
177
- func IterateOrderedMap [K cmp.Ordered , V any ](m map [K ]V ) func (func (K , V ) bool ) {
174
+ func IterateOrderedMap [K cmp.Ordered , V any ](m map [K ]V ) iter.Seq2 [K , V ] {
178
175
keys := make ([]K , 0 , len (m ))
179
176
for key := range m {
180
177
keys = append (keys , key )
Original file line number Diff line number Diff line change @@ -85,18 +85,10 @@ func TestIterateOrderedMap(t *testing.T) {
85
85
for _ , tt := range tests {
86
86
t .Run (tt .name , func (t * testing.T ) {
87
87
var outKeys []int
88
-
89
- // Either run with GOEXPERIMENT=rangefunc or wait for rangefuncs to land in the next Go release.
90
- // for k, _ := range IterateOrderedMap(tt.in) {
91
- // outKeys = append(outKeys, k)
92
- // }
93
-
94
- // In the meantime, it can be invoked as follows.
95
- IterateOrderedMap (tt .in )(func (k int , v string ) bool {
88
+ for k , v := range IterateOrderedMap (tt .in ) {
96
89
assert .Equal (t , tt .in [k ], v )
97
90
outKeys = append (outKeys , k )
98
- return true
99
- })
91
+ }
100
92
101
93
assert .Equal (t , tt .outKeys , outKeys )
102
94
})
You can’t perform that action at this time.
0 commit comments