iter-ops raised above assign; 'cat' operator returns an iterator; $$ operator supports iterators producing a list of items
This commit is contained in:
@@ -7,6 +7,7 @@ package kern
|
||||
import (
|
||||
// "errors"
|
||||
"fmt"
|
||||
"slices"
|
||||
)
|
||||
|
||||
// Operator names
|
||||
@@ -50,3 +51,45 @@ func IsIterator(v any) (ok bool) {
|
||||
_, ok = v.(Iterator)
|
||||
return
|
||||
}
|
||||
|
||||
type IteratorBase struct {
|
||||
ItemIndex int64
|
||||
ItemCount int64
|
||||
current any
|
||||
}
|
||||
|
||||
func (it *IteratorBase) Current() (item any, err error) {
|
||||
return it.current, nil
|
||||
}
|
||||
|
||||
func (it *IteratorBase) Index() int64 {
|
||||
return it.ItemIndex
|
||||
}
|
||||
|
||||
func (it *IteratorBase) Count() int64 {
|
||||
return it.ItemCount
|
||||
}
|
||||
|
||||
func (it *IteratorBase) HasOperation(name string) bool {
|
||||
return slices.Contains([]string{NextName, IndexName, CountName, CurrentName}, name)
|
||||
}
|
||||
|
||||
func (it *IteratorBase) Clean() (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (it *IteratorBase) Reset() (err error) {
|
||||
it.ItemIndex = -1
|
||||
it.ItemCount = 0
|
||||
it.current = nil
|
||||
return
|
||||
}
|
||||
|
||||
func (it *IteratorBase) Increment() {
|
||||
it.ItemIndex++
|
||||
it.ItemCount++
|
||||
}
|
||||
|
||||
func (it *IteratorBase) SetCurrent(v any) {
|
||||
it.current = v
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user