MCPcopy Index your code
hub / github.com/expr-lang/expr / cases

Function cases

vm/runtime/helpers/main.go:58–91  ·  view source on GitHub ↗
(op string, xs ...[]string)

Source from the content-addressed store, hash-verified

56}
57
58func cases(op string, xs ...[]string) string {
59 var types []string
60 for _, x := range xs {
61 types = append(types, x...)
62 }
63
64 _, _ = fmt.Fprintf(os.Stderr, "Generating %s cases for %v\n", op, types)
65
66 var out string
67 echo := func(s string, xs ...any) {
68 out += fmt.Sprintf(s, xs...) + "\n"
69 }
70 for _, a := range types {
71 echo(`case %v:`, a)
72 echo(`switch y := b.(type) {`)
73 for _, b := range types {
74 t := "int"
75 if isDuration(a) || isDuration(b) {
76 t = "time.Duration"
77 }
78 if isFloat(a) || isFloat(b) {
79 t = "float64"
80 }
81 echo(`case %v:`, b)
82 if op == "/" {
83 echo(`return float64(x) / float64(y)`)
84 } else {
85 echo(`return %v(x) %v %v(y)`, t, op, t)
86 }
87 }
88 echo(`}`)
89 }
90 return strings.TrimRight(out, "\n")
91}
92
93func arrayEqualCases(xs ...[]string) string {
94 var types []string

Callers 1

mainFunction · 0.85

Calls 4

isDurationFunction · 0.85
isFloatFunction · 0.85
FprintfMethod · 0.80
SprintfMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…