// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com). // All rights reserved. // iterator.go package kern import ( // "errors" "fmt" ) // Operator names const ( InitName = "init" CleanName = "clean" ResetName = "reset" NextName = "next" CurrentName = "current" IndexName = "index" CountName = "count" FilterName = "filter" MapName = "map" KeyName = "key" ValueName = "value" ) type Iterator interface { Typer fmt.Stringer Next() (item any, err error) // must return io.EOF after the last item Current() (item any, err error) Index() int64 Count() int64 HasOperation(name string) bool CallOperation(name string, args map[string]any) (value any, err error) } type ExtIterator interface { Iterator Reset() error Clean() error } func ErrNoOperation(name string) error { return fmt.Errorf("no %s() function defined in the data-source", name) } func IsIterator(v any) (ok bool) { _, ok = v.(Iterator) return }