2024-04-13 06:00:22 +02:00
|
|
|
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
|
|
|
// All rights reserved.
|
|
|
|
|
2024-03-30 06:56:12 +01:00
|
|
|
// iterator.go
|
|
|
|
package expr
|
|
|
|
|
2024-05-01 05:46:24 +02:00
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
)
|
2024-04-28 06:45:20 +02:00
|
|
|
|
2024-05-04 08:07:49 +02:00
|
|
|
// Operator names
|
|
|
|
|
|
|
|
const (
|
|
|
|
initName = "init"
|
|
|
|
cleanName = "clean"
|
|
|
|
resetName = "reset"
|
|
|
|
nextName = "next"
|
|
|
|
currentName = "current"
|
|
|
|
indexName = "index"
|
|
|
|
countName = "count"
|
|
|
|
)
|
|
|
|
|
2024-03-30 06:56:12 +01:00
|
|
|
type Iterator interface {
|
|
|
|
Next() (item any, err error) // must return io.EOF after the last item
|
2024-04-26 04:30:43 +02:00
|
|
|
Current() (item any, err error)
|
2024-03-30 06:56:12 +01:00
|
|
|
Index() int
|
2024-05-04 00:28:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type ExtIterator interface {
|
|
|
|
Iterator
|
2024-04-28 06:45:20 +02:00
|
|
|
HasOperation(name string) bool
|
|
|
|
CallOperation(name string, args []any) (value any, err error)
|
|
|
|
}
|
|
|
|
|
|
|
|
func errNoOperation(name string) error {
|
|
|
|
return fmt.Errorf("no %q function defined in the data-source", name)
|
2024-03-30 06:56:12 +01:00
|
|
|
}
|
2024-05-01 05:46:24 +02:00
|
|
|
|
|
|
|
func errInvalidDataSource() error {
|
|
|
|
return errors.New("invalid data-source")
|
|
|
|
}
|