Skip to content
This repository was archived by the owner on Mar 16, 2025. It is now read-only.

Commit aa4bf08

Browse files
committed
allow to specify a forced coalescer for a native function
1 parent 7f795a0 commit aa4bf08

1 file changed

Lines changed: 17 additions & 6 deletions

File tree

pkg/eval/util/native/function.go

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,20 @@ import (
77
"errors"
88
"fmt"
99

10+
"go.xrstf.de/rudi/pkg/coalescing"
1011
"go.xrstf.de/rudi/pkg/eval/types"
1112
"go.xrstf.de/rudi/pkg/lang/ast"
1213
)
1314

14-
type function struct {
15+
type Function struct {
1516
forms []form
17+
coalescer coalescing.Coalescer
1618
description string
1719
}
1820

19-
var _ types.Function = &function{}
21+
var _ types.Function = &Function{}
2022

21-
func NewFunction(description string, funcs ...any) types.Function {
23+
func NewFunction(description string, funcs ...any) *Function {
2224
forms := make([]form, len(funcs))
2325

2426
for i := range funcs {
@@ -30,19 +32,28 @@ func NewFunction(description string, funcs ...any) types.Function {
3032
forms[i] = funcForm
3133
}
3234

33-
return &function{
35+
return &Function{
3436
forms: forms,
3537
description: description,
3638
}
3739
}
3840

39-
func (f *function) Description() string {
41+
func (f *Function) Description() string {
4042
return f.description
4143
}
4244

43-
func (f *function) Evaluate(ctx types.Context, args []ast.Expression) (any, error) {
45+
func (f *Function) WithCoalescer(c coalescing.Coalescer) *Function {
46+
f.coalescer = c
47+
return f
48+
}
49+
50+
func (f *Function) Evaluate(ctx types.Context, args []ast.Expression) (any, error) {
4451
cachedArgs := convertArgs(args)
4552

53+
if f.coalescer != nil {
54+
ctx = ctx.WithCoalescer(f.coalescer)
55+
}
56+
4657
for i, form := range f.forms {
4758
matched, err := form.Match(ctx, cachedArgs)
4859
if err != nil {

0 commit comments

Comments
 (0)