IF Commons GitHub

extensions/query/selection

Lazy typed selections of nodes (commons lang-sql 0003-sql-ast-tools FR-006): select(root) begins one, each method makes another over what the last gives, and the kind a method is given types the result.

Spec: 0003-sql-ast-tools FR-006

Source: commons/lang-sql/src/extensions/query/selection.ts

1 of 2 exports are imported by a test of the run. A test that imports an export may not call it or check what it returns.

Selectionclassno test imports it
class Selection<T extends Node> implements Iterable<T>

A lazy set of nodes of one type, in the order they were found; it can be read again.

MemberTypeWhat it is
run() => Iterable<T>
parents() => ParentIndex
__@iterator@281474976710661() => Iterator<T, any, any>
children() => Selection<Node>The children of each node.
descendants() => Selection<Node>Every node below each node, in the order of the text.
find<K extends Kind>(kind: K) => Selection<NodeOf<K>>The nodes of a kind below each node, typed as that kind.
ofKind<K extends Kind>(kind: K) => Selection<NodeOf<K>>The nodes of a kind among these, typed as that kind.
where{ <U extends T>(test: (n: T) => n is U): Selection<U>; (test: (n: T) => boolean): Selection<T>; }The nodes for which a test holds; a type guard types the result.
map<U extends Node>(f: (n: T) => U | undefined) => Selection<U>What f makes of each node; a node it makes nothing of (undefined) is left out.
flatMap<U extends Node>(f: (n: T) => Iterable<U>) => Selection<U>The nodes f makes of each node, one after the other.
parent() => Selection<Node>The parent of each node.
ancestors() => Selection<Node>The ancestors of each node, nearest first.
closest<K extends Kind>(kind: K) => Selection<NodeOf<K>>For each node, the nearest of it and its ancestors that is of the kind.
unique() => Selection<T>The nodes with the repeats left out.
toArray() => T[]The nodes, in an array.
first() => T | undefinedThe first node, or undefined.
count() => numberHow many nodes.
some(test: (n: T) => boolean) => booleanWhether a test holds for some node.
every(test: (n: T) => boolean) => booleanWhether a test holds for every node.
selectfunction
function select(root: Node): Selection<Node>

Begins a selection with one node.

ParameterWhat it is
rootthe node, usually a script

Returns: a selection of it; its parents are found once, when one is first asked for

Imported by 4 tests of the run (4 passed, 0 failed): the library's results

Titles, headings, exports, tables, columns and requirements. Esc closes.