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

Filterx function path lookup #450

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

bshifter
Copy link
Member

@bshifter bshifter commented Jan 8, 2025

Add path_lookup to the filterx_object Namespace as an Alternative to get_subscript

This PR introduces a new function, path_lookup, to the filterx_object namespace. It allows retrieving elements from nested filterx lists or dictionaries in a single call, providing a more convenient and expressive alternative to using get_subscript repeatedly.

Key Features:

  • Flexible First Argument: The first argument must be a list or dictionary. Mixed structures (e.g., nested combinations of lists and dictionaries) are fully supported.
  • Dynamic Path Lookup: The second parameter accepts a list literal containing both filterx strings (for dictionary keys) and integers (for list indices).
  • Deep Nested Access: Enables seamless access to deeply nested elements in hybrid list-dictionary structures.
  • Reverse Indexing Support: Integer indices support negative values for reverse indexing in lists, mirroring Python-like behavior.

example:

filterx {
d = {"foo":1,"bar":[3,2,1],"baz":{"tik":"tak"}};
a = path_lookup(d, ["bar", 0]); # returns 3
b = path_lookup(d, ["baz", "tik"]); # returns "tak"
c = path_lookup(d, ["bar", -1]); # returns 1
}

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

Successfully merging this pull request may close these issues.

1 participant