mirror of
https://github.com/wader/fq.git
synced 2024-12-29 00:22:38 +03:00
42 lines
1.5 KiB
Cheetah
42 lines
1.5 KiB
Cheetah
// Generated from makefn_gen.go.tmpl
|
|
package gojqex
|
|
|
|
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}}
|
|
|
|
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 {
|
|
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}}
|
|
|
|
return fn(env, cv{{range $i := xrange 0 $args}}, a{{$i}}{{end}})
|
|
}
|
|
return f
|
|
}
|
|
}
|
|
{{- end}}
|
|
{{- end}}
|