mirror of
https://github.com/MontFerret/ferret.git
synced 2024-12-23 01:24:30 +02:00
40 lines
777 B
Go
40 lines
777 B
Go
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
|
|
}
|