Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Does the element of the slice have to be a struct #486

Closed Answered by lirui001
lirui001 asked this question in Q&A
Discussion options

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')})
| .......................^

You must be logged in to vote

Replies: 1 comment

Comment options

has answed

You must be logged in to vote
0 replies
Answer selected by lirui001
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant

AltStyle によって変換されたページ (->オリジナル) /