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 (
|
2024-07-18 07:27:02 +02:00
|
|
|
InitName = "init"
|
|
|
|
CleanName = "clean"
|
|
|
|
ResetName = "reset"
|
|
|
|
NextName = "next"
|
|
|
|
CurrentName = "current"
|
|
|
|
IndexName = "index"
|
|
|
|
CountName = "count"
|
|
|
|
FilterName = "filter"
|
|
|
|
MapName = "map"
|
2024-05-04 08:07:49 +02:00
|
|
|
)
|
|
|
|
|
2024-03-30 06:56:12 +01:00
|
|
|
type Iterator interface {
|
2024-07-06 04:51:11 +02:00
|
|
|
Typer
|
2024-03-30 06:56:12 +01:00
|
|
|
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-07-21 16:34:52 +02:00
|
|
|
Count() 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 {
|
2024-06-05 08:06:39 +02:00
|
|
|
return fmt.Errorf("no %s() 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")
|
|
|
|
}
|