-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Proposal: add elipsis matching for arrays #1812
Comments
This can be helped with, a little, by a helper definition: path_prefix := {q | q := array.slice(input.path, 0, j + 1); input.path[j]} This lets then use path_prefix[["root", "private"]] where we'd have liked to match with
|
While I like this, is there something this provides more than what is shown in the example here? input.path == ["root", "private", ...] could be: input.path[:2] == ["root", "private"] Having a more powerful way of expressing array slices would have quite a few more benefits, like slicing from the end of the array, providing a custom |
Discussing this with @srenatus, it would be pretty neat if an elipsis operator would encompass objects as well, so you could do object destructuring like: some {"name": name, "permissions": permissions, ...} in input.user.attributes And perhaps it could be used to match parts of an object as well: {"a: 1, "b": 2, ...} == {"a": 1, "b": 2, "c": 3} |
@johanfylling had an interesting case for this, where he wanted to do pattern matching for "last in path" without knowing the length of the array, e.g. something like walk(object, [[..., "modules"], value]) |
I could also see the elipsis operator being useful for referencing documents at arbitrarily deep paths for dynamic composition... for example:
|
When we want to match each of these paths,
and only care for them to start with
["root", "private"]
, it would me nice if we could sayand had it match all of
path1
,path2
, andpath3
.Right now, we have to explicitly state
to make it match those three paths.
The text was updated successfully, but these errors were encountered: