-
-
Notifications
You must be signed in to change notification settings - Fork 464
-
In my expression, i want to use any,but my slice element is string,for example []int,i don't know how to get the element about the slice, The following is a concrete example:
In your example:
`package main
import (
"fmt"
"github.com/antonmedv/expr"
)
type Tweet struct {
Len int
}
type Env struct {
Tweets []Tweet
}
func main() {
code := all(Tweets, {.Len <= 240})
program, err := expr.Compile(code, expr.Env(Env{}))
if err != nil {
panic(err)
}
env := Env{
Tweets: []Tweet{{42}, {98}, {69}},
}
output, err := expr.Run(program, env)
if err != nil {
panic(err)
}
fmt.Println(output)
}`
In my example:
`package main
import (
"fmt"
"github.com/antonmedv/expr"
)
type Tweet struct {
Len int
}
type Env struct {
Tweets []int
}
func main() {
code := all(Tweets, {.<= 240})
program, err := expr.Compile(code, expr.Env(Env{}))
if err != nil {
panic(err)
}
env := Env{
Tweets: []{42, 98, 69},
}
output, err := expr.Run(program, env)
if err != nil {
panic(err)
}
fmt.Println(output)
}`
the expression compile error:
Error compiling expression: expected name (1:24)
| any(Path, {Contains(., 'ba')})
| .......................^
Beta Was this translation helpful? Give feedback.
All reactions
has answed
Replies: 1 comment
-
has answed
Beta Was this translation helpful? Give feedback.