-
-
Notifications
You must be signed in to change notification settings - Fork 463
-
One of the examples on the playground is
tweets | filter(.Content contains "Hello") | map(.User) | first()
which is very sleek and elegant. However, what would be even more convenient is
tweets | find(.Content contains "Hello") | .User
Is there anything I'm missing to make this work?
There's
tweets | find(.Content contains "Hello") | get("User")
but now you're losing type-safety, I suppose.
Beta Was this translation helpful? Give feedback.
All reactions
In Expr, pipes designed to always work with function. Expr parser checks if there is a function call after a pipe. This approach simplifies a lot of things and makes syntax consistent.
One way to solve it is to use variables.
let user = tweets | find(.Content contains "Hello"); user.User
The get built-in keep it's type information. It's a special built-in and have a special handling in type check.
Replies: 1 comment 3 replies
-
In Expr, pipes designed to always work with function. Expr parser checks if there is a function call after a pipe. This approach simplifies a lot of things and makes syntax consistent.
One way to solve it is to use variables.
let user = tweets | find(.Content contains "Hello"); user.User
The get built-in keep it's type information. It's a special built-in and have a special handling in type check.
Beta Was this translation helpful? Give feedback.
All reactions
-
Thank you for the swift response! That's a reasonable workaround 👍
For what it's worth, I don't know if it's worth considering, but maybe - given the constraint you outlined - a new function like get that takes a membership expression instead of a string would be nice. Like:
tweets | find(.Content contains "Hello") | get(.User)
Just throwing it out there :)
Beta Was this translation helpful? Give feedback.
All reactions
-
Nice idea actually. Only a few coronal cases which need to be understood.
get(.User.Name) get(.Func()) get(.Math + 42) get(42)
Beta Was this translation helpful? Give feedback.
All reactions
-
I'd disallow anything that isn't a membership operation (ie the first line), to be honest.
Beta Was this translation helpful? Give feedback.