1
0
mirror of https://github.com/MontFerret/ferret.git synced 2024-12-16 11:37:36 +02:00
ferret/pkg/runtime/collections/tap.go

40 lines
777 B
Go
Raw Normal View History

2018-10-28 07:45:26 +02:00
package collections
import (
"context"
"github.com/MontFerret/ferret/pkg/runtime/core"
)
type TapIterator struct {
values Iterator
predicate core.Expression
}
func NewTapIterator(values Iterator, predicate core.Expression) (Iterator, error) {
if values == nil {
return nil, core.Error(core.ErrMissedArgument, "values")
}
if predicate == nil {
return nil, core.Error(core.ErrMissedArgument, "predicate")
}
return &TapIterator{values, predicate}, nil
}
func (iterator *TapIterator) Next(ctx context.Context, scope *core.Scope) (*core.Scope, error) {
nextScope, err := iterator.values.Next(ctx, scope)
if err != nil {
return nil, err
}
_, err = iterator.predicate.Exec(ctx, nextScope)
if err != nil {
return nil, err
}
return nextScope, nil
}