2022-07-16 19:39:57 +03:00
|
|
|
// Generated from makefn_gen.go.tmpl
|
2022-08-12 16:27:51 +03:00
|
|
|
package gojqex
|
2022-07-16 19:39:57 +03:00
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/wader/fq/internal/mapstruct"
|
|
|
|
"github.com/wader/gojq"
|
|
|
|
)
|
|
|
|
{{- $counts := map 0 "first" 1 "second" 2 "third"}}
|
|
|
|
{{- range $fn := slice (map "name" "Func" "type" "any" "field" "FuncFn") (map "name" "Iter" "type" "gojq.Iter" "field" "IterFn") }}
|
|
|
|
{{- range $args := xrange 0 4}}
|
|
|
|
|
2022-07-16 22:54:32 +03:00
|
|
|
func {{$fn.name}}{{$args}}[Tenv any, Tc any{{range $i := xrange 0 $args}}, Ta{{$i}} any{{end}}](name string, fn func(e Tenv, c Tc{{range $i := xrange 0 $args}}, a{{$i}} Ta{{$i}}{{end}}) {{$fn.type}}) func(env Tenv) Function {
|
|
|
|
return func(env Tenv) Function {
|
2022-07-16 19:39:57 +03:00
|
|
|
f := Function{Name: name, MinArity: {{$args}}, MaxArity: {{$args}}}
|
|
|
|
f.{{$fn.field}} = func(c any, a []any) {{$fn.type}} {
|
|
|
|
cv, ok := CastFn[Tc](c, mapstruct.ToStruct)
|
|
|
|
if !ok {
|
|
|
|
{{- if eq $fn.name "Func"}}
|
|
|
|
return FuncTypeError{Name: name, V: c}
|
|
|
|
{{- else}}
|
|
|
|
return gojq.NewIter(FuncTypeError{Name: name, V: c})
|
|
|
|
{{- end}}
|
|
|
|
}
|
|
|
|
{{- range $i := xrange 0 $args}}
|
|
|
|
a{{$i}}, ok := CastFn[Ta{{$i}}](a[{{$i}}], mapstruct.ToStruct)
|
|
|
|
if !ok {
|
|
|
|
{{- if eq $fn.name "Func"}}
|
|
|
|
return FuncArgTypeError{Name: name, ArgName: "{{index $counts $i}}", V: a[{{$i}}]}
|
|
|
|
{{- else}}
|
|
|
|
return gojq.NewIter(FuncArgTypeError{Name: name, ArgName: "{{index $counts $i}}", V: a[{{$i}}]})
|
|
|
|
{{- end}}
|
|
|
|
}
|
|
|
|
{{- end}}
|
|
|
|
|
2022-07-16 22:54:32 +03:00
|
|
|
return fn(env, cv{{range $i := xrange 0 $args}}, a{{$i}}{{end}})
|
2022-07-16 19:39:57 +03:00
|
|
|
}
|
|
|
|
return f
|
|
|
|
}
|
|
|
|
}
|
|
|
|
{{- end}}
|
|
|
|
{{- end}}
|