Skip to content
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

Check if data exists in collections #746

Closed
xushiwei opened this issue Jul 30, 2021 · 1 comment
Closed

Check if data exists in collections #746

xushiwei opened this issue Jul 30, 2021 · 1 comment

Comments

@xushiwei
Copy link
Member

xushiwei commented Jul 30, 2021

As #675, we have support selecting data from collections:

selected := {x.score for x <- a, x.name == "du"}
selected, ok := {x.score for x <- a, x.name == "du"}

Now we can support a special case of this form:

exists := {for x <- a, x.name == "du"}

That is, we don't select any data, but only check if data exists or not. For example:

type student struct {
	name  string
	score int
}

a := [student{"ken", 90}, student{"du", 84}, student{"wang", 70}]

duScore := {x.score for x <- a, x.name == "du"}
unknownScore, ok := {x.score for x <- a, x.name == "unknown"}

hasFailed := {for x <- a, x.score < 60}  // is any student failed?
hasFullMark := {for x <- a, x.score == 100} // is any student full mark?
@xushiwei
Copy link
Member Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant