Skip to content

Navigation Menu

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

Appearance settings

Why can't I use the membership operator together with the pipe operator? #780

Answered by antonmedv
stephanos asked this question in Q&A
Discussion options

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.

You must be logged in to vote

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

Comment options

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.

You must be logged in to vote
3 replies
@stephanos
Comment options

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 :)

@antonmedv
Comment options

Nice idea actually. Only a few coronal cases which need to be understood.

get(.User.Name)
get(.Func())
get(.Math + 42)
get(42)
@stephanos
Comment options

I'd disallow anything that isn't a membership operation (ie the first line), to be honest.

Answer selected by stephanos
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
🙏
Q&A
Labels
None yet
2 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.