44 lines
832 B
Go
44 lines
832 B
Go
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
|
// All rights reserved.
|
|
|
|
// iterator.go
|
|
package expr
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
)
|
|
|
|
// Operator names
|
|
|
|
const (
|
|
initName = "init"
|
|
cleanName = "clean"
|
|
resetName = "reset"
|
|
nextName = "next"
|
|
currentName = "current"
|
|
indexName = "index"
|
|
countName = "count"
|
|
)
|
|
|
|
type Iterator interface {
|
|
Typer
|
|
Next() (item any, err error) // must return io.EOF after the last item
|
|
Current() (item any, err error)
|
|
Index() int
|
|
}
|
|
|
|
type ExtIterator interface {
|
|
Iterator
|
|
HasOperation(name string) bool
|
|
CallOperation(name string, args []any) (value any, err error)
|
|
}
|
|
|
|
func errNoOperation(name string) error {
|
|
return fmt.Errorf("no %s() function defined in the data-source", name)
|
|
}
|
|
|
|
func errInvalidDataSource() error {
|
|
return errors.New("invalid data-source")
|
|
}
|