File tree Expand file tree Collapse file tree 1 file changed +23
-5
lines changed Expand file tree Collapse file tree 1 file changed +23
-5
lines changed Original file line number Diff line number Diff line change @@ -6,16 +6,34 @@ import (
6
6
"github.com/zclconf/go-cty/cty/set"
7
7
)
8
8
9
+ // GoIter returns a [iter.Seq2[cty.Value, cty.Value]] iterator that iterates over
10
+ // the elements of a collection-typed value, yielding each element's key and
11
+ // value in turn.
12
+ // From Go 1.23, this can be used as follows:
13
+ //
14
+ // for key, val := range cty.GoIter(val) {
15
+ // // ...
16
+ // }
17
+ func GoIter (val Value ) func (yield func (Value , Value ) bool ) {
18
+ return func (yield func (Value , Value ) bool ) {
19
+ for it := val .ElementIterator (); it .Next (); {
20
+ if ! yield (it .Element ()) {
21
+ return
22
+ }
23
+ }
24
+ }
25
+ }
26
+
9
27
// ElementIterator is the interface type returned by Value.ElementIterator to
10
28
// allow the caller to iterate over elements of a collection-typed value.
11
29
//
12
30
// Its usage pattern is as follows:
13
31
//
14
- // it := val.ElementIterator()
15
- // for it.Next() {
16
- // key, val := it.Element()
17
- // // ...
18
- // }
32
+ // it := val.ElementIterator()
33
+ // for it.Next() {
34
+ // key, val := it.Element()
35
+ // // ...
36
+ // }
19
37
type ElementIterator interface {
20
38
Next () bool
21
39
Element () (key Value , value Value )
You can’t perform that action at this time.
0 commit comments