expr/iterator.go

46 lines
877 B
Go
Raw Normal View History

// 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"
FilterName = "filter"
MapName = "map"
)
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")
}