data-cursor.go: added Reset() e Clean() functions
This commit is contained in:
parent
327bffa01f
commit
354cb79580
@ -10,6 +10,8 @@ import (
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
initName = "init"
|
initName = "init"
|
||||||
|
cleanName = "clean"
|
||||||
|
resetName = "reset"
|
||||||
nextName = "next"
|
nextName = "next"
|
||||||
currentName = "current"
|
currentName = "current"
|
||||||
)
|
)
|
||||||
@ -20,6 +22,8 @@ type dataCursor struct {
|
|||||||
index int
|
index int
|
||||||
resource any
|
resource any
|
||||||
nextFunc Functor
|
nextFunc Functor
|
||||||
|
cleanFunc Functor
|
||||||
|
resetFunc Functor
|
||||||
currentFunc Functor
|
currentFunc Functor
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -35,6 +39,26 @@ func (dc *dataCursor) String() string {
|
|||||||
return "$(...)"
|
return "$(...)"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (dc *dataCursor) Reset() (err error) {
|
||||||
|
if dc.resetFunc != nil {
|
||||||
|
ctx := cloneContext(dc.ctx)
|
||||||
|
if _, err = dc.resetFunc.Invoke(ctx, resetName, []any{}); err == nil {
|
||||||
|
dc.index = -1
|
||||||
|
}
|
||||||
|
exportObjects(dc.ctx, ctx)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (dc *dataCursor) Clean() (err error) {
|
||||||
|
if dc.resetFunc != nil {
|
||||||
|
ctx := cloneContext(dc.ctx)
|
||||||
|
_, err = dc.cleanFunc.Invoke(ctx, cleanName, []any{})
|
||||||
|
exportObjects(dc.ctx, ctx)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func (dc *dataCursor) Current() (item any, err error) { // must return io.EOF at the last item
|
func (dc *dataCursor) Current() (item any, err error) { // must return io.EOF at the last item
|
||||||
ctx := cloneContext(dc.ctx)
|
ctx := cloneContext(dc.ctx)
|
||||||
if item, err = dc.currentFunc.Invoke(ctx, currentName, []any{}); err == nil && item == nil {
|
if item, err = dc.currentFunc.Invoke(ctx, currentName, []any{}); err == nil && item == nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user