-
-
Notifications
You must be signed in to change notification settings - Fork 402
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature Request: Types implementing "fmt.Stringer" should be assignable/comparable to strings #648
Comments
Hello 👋🏻, This is a good suggestion. I think it was already proposed multiple times. Although I believe this should not be a default behavior, we can create an official patcher (https://github.com/expr-lang/expr/tree/master/patcher) for fmt.Stringer interface. This new patcher will automatically add
Also let's modify Like in next situation,
|
There was some similar discussion around this for the Off the top of my head |
being able to pick |
@jippi You could take a look at https://pkg.go.dev/github.com/expr-lang/[email protected]/patcher/value and see if that does what you want (specifically implementing https://pkg.go.dev/github.com/expr-lang/[email protected]/patcher/value#StringValuer). |
The valuer worked for me 👍 though it was a bit tedious having to repeat this code a handful of times func (d MyType) AsString() string {
return d.String()
} That being said, I do understand why not supporting Having the |
Could you tell what do you miss in the docs? |
👋 Hello,
I got the following error with this expression:
merge_request.state in ["merged", "closed"]
reflect.Value.MapIndex: value of type gitlab.MergeRequestState is not assignable to type string
It would be very nice if types implementing
fmt.Stringer
interface to be assignable to strings, or generally treated as strings.Alternatively, a
expr
interface types could implement, making them capable of self-casting to various scalar types.For reference this is the
gitlab.MergeRequestState
type (used inmerge_request.state
) implementationThe text was updated successfully, but these errors were encountered: