query
local query = require("@std/syntax/query")query.filter
Retains only the nodes for which pred returns true. Mutates and returns the query.
(self: Query<T>, pred: (T) -> boolean) -> Query<T>query.findAll
Recursively visits every descendant of each node in the query and collects those for which fn returns a non-nil value. Mutates and returns the query.
(self: Query<T>, fn: (Node) -> U?) -> Query<U>query.findAllFromRoot
Creates a new Query by visiting every node in ast and collecting those for which fn returns a non-nil value.
(ast: types.ParseResult | Node, fn: (Node) -> T?) -> Query<T>query.flatMap
Replaces each node with the array of values returned by fn, flattening one level. Mutates and returns the query.
(self: Query<T>, fn: (T) -> { U }) -> Query<U>query.forEach
Calls callback on each node. Returns the query unchanged for chaining.
(self: Query<T>, callback: (T) -> ()) -> Query<T>query.map
Replaces the query's nodes with the non-nil values returned by fn for each node. Mutates and returns the query.
(self: Query<T>, fn: (T) -> U?) -> Query<U>query.mapToArray
Returns a plain array of the non-nil values produced by calling fn on each node. Does not mutate the query.
(self: Query<T>, fn: (T) -> U?) -> { U }query.replace
Calls repl on each node and collects the non-nil results into a Replacements table for use with the printer.
(self: Query<T>, repl: (T) -> string?) -> types.Replacements