-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
iterator.go
66 lines (52 loc) · 1.74 KB
/
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package common
import (
"bufio"
"fmt"
"github.com/inoxlang/inox/internal/core"
"github.com/inoxlang/inox/internal/core/symbolic"
"github.com/inoxlang/inox/internal/utils"
)
type CollectionIterator struct {
HasNext_ func(*CollectionIterator, *core.Context) bool
Next_ func(*CollectionIterator, *core.Context) bool
Key_ func(*CollectionIterator, *core.Context) core.Value
Value_ func(*CollectionIterator, *core.Context) core.Value
}
func NewEmptyCollectionIterator() *CollectionIterator {
return &CollectionIterator{
HasNext_: func(ci *CollectionIterator, ctx *core.Context) bool {
return false
},
}
}
func (it *CollectionIterator) HasNext(ctx *core.Context) bool {
return it.HasNext_(it, ctx)
}
func (it *CollectionIterator) Next(ctx *core.Context) bool {
if !it.HasNext(ctx) {
return false
}
return it.Next_(it, ctx)
}
func (it *CollectionIterator) Key(ctx *core.Context) core.Value {
return it.Key_(it, ctx)
}
func (it *CollectionIterator) Value(ctx *core.Context) core.Value {
return it.Value_(it, ctx)
}
func (it *CollectionIterator) Iterator(ctx *core.Context, config core.IteratorConfiguration) core.Iterator {
return it
}
func (it *CollectionIterator) IsMutable() bool {
return true
}
func (it *CollectionIterator) Equal(ctx *core.Context, other core.Value, alreadyCompared map[uintptr]uintptr, depth int) bool {
otherIt, ok := other.(*CollectionIterator)
return ok && it == otherIt
}
func (it *CollectionIterator) ToSymbolicValue(ctx *core.Context, encountered map[uintptr]symbolic.Value) (symbolic.Value, error) {
return nil, symbolic.ErrNoSymbolicValue
}
func (it *CollectionIterator) PrettyPrint(w *bufio.Writer, config *core.PrettyPrintConfig, depth int, parentIndentCount int) {
utils.Must(fmt.Fprintf(w, "%#v", it))
}