forked from MontFerret/ferret
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tap.go
43 lines (32 loc) · 822 Bytes
/
tap.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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
}
if nextScope == nil {
return nil, nil
}
_, err = iterator.predicate.Exec(ctx, nextScope)
if err != nil {
return nil, err
}
return nextScope, nil
}