-
Notifications
You must be signed in to change notification settings - Fork 0
/
iterator.go
45 lines (34 loc) · 907 Bytes
/
iterator.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package jsonx
import "context"
type documentIterImpl struct {
idx int
doc *Document
current *Element
err error
}
func (iter *documentIterImpl) Next(ctx context.Context) bool {
if iter.idx+1 > iter.doc.Len() || ctx.Err() != nil {
return false
}
iter.current = iter.doc.elems[iter.idx].Copy()
iter.idx++
return true
}
func (iter *documentIterImpl) Value() *Element { return iter.current }
func (iter *documentIterImpl) Close() error { return nil }
type arrayIterImpl struct {
idx int
array *Array
current *Value
err error
}
func (iter *arrayIterImpl) Next(ctx context.Context) bool {
if iter.idx+1 > iter.array.Len() || ctx.Err() != nil {
return false
}
iter.current = iter.array.elems[iter.idx].Copy()
iter.idx++
return true
}
func (iter *arrayIterImpl) Value() *Value { return iter.current }
func (iter *arrayIterImpl) Close() error { return nil }