1
0
mirror of https://github.com/MontFerret/ferret.git synced 2024-12-14 11:23:02 +02:00
ferret/pkg/runtime/collections/iterator.go
Tim Voronov 549b4abd3b
Feature/#5 collect keyword alt (#141)
Implemented COLLECT key word
2018-10-24 21:30:05 -04:00

37 lines
540 B
Go

package collections
import (
"context"
"github.com/MontFerret/ferret/pkg/runtime/core"
)
type (
Variables []string
Iterator interface {
HasNext() bool
Next() (DataSet, error)
}
Iterable interface {
Variables() Variables
Iterate(ctx context.Context, scope *core.Scope) (Iterator, error)
}
)
func ToSlice(iterator Iterator) ([]DataSet, error) {
res := make([]DataSet, 0, 10)
for iterator.HasNext() {
ds, err := iterator.Next()
if err != nil {
return nil, err
}
res = append(res, ds)
}
return res, nil
}