Iterator
Last updated
Last updated
[data/tree/Iterator]
Iterates over nodes in a tree (deeply nested object) structure, as specified by the query.
The query
acts as a filter for the iteration. It could hold strings for object keys, numbers for array indices, or objects describing either catch-all or a set of keys to include.
An example query
: ["foo", 1, {"type":"wildcard"}, {"type":"options", "options": ["bar", "baz"]}]
Example:
{"foo": [0, {"a": { "bar": 1 }, "b": { "baz": 1 }}]}@0 is received via tree
["foo", 1, {"type":"wildcard"}, {"type":"options", "options": ["bar", "baz"]}]@0 is received via query
["foo", 1, "a", "bar"]@0:0 is sent via path
1@0:0 is sent via node
the original tree
is sent via tree
["foo", 1, "a", "baz"]@0:1 is sent via path
1@0:1 is sent via node
the original tree
is sent via tree
null@0 is sent via done
Keywords: tree, iterator, foreach
tree: (any[] or {string: any})
The tree data structure to iterate over on.
query:
Pattern for paths. Array of strings, numbers or expressions. Strings look for exact matches, numbers for array indices and expressions describe matching mechanisms. {"type": "wildcard"} Matches any key in the current node. {"type": "options", "options":[]} Matches the listed keys.
path: (string or number)[]
Sends the current path in the iteration
node: any
Sends the current node in the iteration
tree: (any[] or {string: any})
Sends the entire tree
done: null
Sends null when the iteration is done