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

$select Support #4

Open
RDIL opened this issue Jan 18, 2023 · 5 comments
Open

$select Support #4

RDIL opened this issue Jan 18, 2023 · 5 comments
Assignees
Labels
enhancement New feature or request

Comments

@RDIL
Copy link
Member

RDIL commented Jan 18, 2023

Add support for that wacky node that Govert found.

@RDIL RDIL added the enhancement New feature or request label Jan 18, 2023
@RDIL RDIL self-assigned this Jan 18, 2023
@AnthonyFuller
Copy link
Contributor

What does it actually do?

@grappigegovert
Copy link
Member

The $select action runs an action for every element in an array that matches a condition
Syntax is like this

"$select": {
  "in": [1, 2, 3],
  "?": {
    "$gt": ["$.#", 1]
  },
  "!": [
    "$inc": ["$.myvariable", "$.#"]
  ]

This would add the values 2 and 3 to the context var myvariable

There are no official contracts or challenges that use it, and afaik the functionality was added in H3.

@AnthonyFuller
Copy link
Contributor

That's actually really nice, I like that.

@AnthonyFuller
Copy link
Contributor

Question: what happens if you just put a number for in, does it just not do anything?

@grappigegovert
Copy link
Member

I'm not entirely sure, but I think it'll crash during loading.
You can do "in": "$.contextVar", just like you can with $all, $any, and $inarray, to use a context var as input array and I think that will do nothing if contextVar is not an array.
I don't have all the behaviour written down yet, so this might be incorrect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Development

No branches or pull requests

3 participants