mirror of
https://github.com/MontFerret/ferret.git
synced 2024-12-14 11:23:02 +02:00
549b4abd3b
Implemented COLLECT key word
45 lines
876 B
Go
45 lines
876 B
Go
package collections
|
|
|
|
import (
|
|
"github.com/MontFerret/ferret/pkg/runtime/core"
|
|
"github.com/MontFerret/ferret/pkg/runtime/values"
|
|
)
|
|
|
|
type SliceIterator struct {
|
|
valVar string
|
|
keyVar string
|
|
values []core.Value
|
|
pos int
|
|
}
|
|
|
|
func NewSliceIterator(
|
|
valVar,
|
|
keyVar string,
|
|
input []core.Value,
|
|
) Iterator {
|
|
return &SliceIterator{valVar, keyVar, input, 0}
|
|
}
|
|
|
|
func NewDefaultSliceIterator(input []core.Value) Iterator {
|
|
return NewSliceIterator(DefaultValueVar, DefaultKeyVar, input)
|
|
}
|
|
|
|
func (iterator *SliceIterator) HasNext() bool {
|
|
return len(iterator.values) > iterator.pos
|
|
}
|
|
|
|
func (iterator *SliceIterator) Next() (DataSet, error) {
|
|
if len(iterator.values) > iterator.pos {
|
|
idx := iterator.pos
|
|
val := iterator.values[idx]
|
|
iterator.pos++
|
|
|
|
return DataSet{
|
|
iterator.valVar: val,
|
|
iterator.keyVar: values.NewInt(idx),
|
|
}, nil
|
|
}
|
|
|
|
return nil, ErrExhausted
|
|
}
|