MCPcopy Index your code
hub / github.com/tinyplex/tinybase / visitTree

Function visitTree

src/common/map.ts:146–178  ·  view source on GitHub ↗
(
  node: Node<Path, Leaf>,
  path: Path[],
  ensureLeaf?: () => Leaf,
  pruneLeaf?: (leaf: Leaf) => 1 | 0 | void,
  p = 0,
)

Source from the content-addressed store, hash-verified

144
145export type Node<Path, Leaf> = Map<Path, Node<Path, Leaf> | Leaf>;
146export const visitTree = <Path, Leaf>(
147 node: Node<Path, Leaf>,
148 path: Path[],
149 ensureLeaf?: () => Leaf,
150 pruneLeaf?: (leaf: Leaf) => 1 | 0 | void,
151 p = 0,
152): Leaf | undefined =>
153 ifNotUndefined(
154 (ensureLeaf ? mapEnsure : mapGet)(
155 node,
156 path[p],
157 p > size(path) - 2 ? (ensureLeaf as () => Leaf) : mapNew,
158 ),
159 (nodeOrLeaf) => {
160 if (p > size(path) - 2) {
161 if (pruneLeaf?.(nodeOrLeaf as Leaf)) {
162 mapSet(node, path[p]);
163 }
164 return nodeOrLeaf as Leaf;
165 }
166 const leaf = visitTree(
167 nodeOrLeaf as Node<Path, Leaf>,
168 path,
169 ensureLeaf,
170 pruneLeaf,
171 p + 1,
172 ) as Leaf;
173 if (collIsEmpty(nodeOrLeaf as Node<Path, Leaf>)) {
174 mapSet(node, path[p]);
175 }
176 return leaf;
177 },
178 );

Callers 3

setQueryDefinitionImplFunction · 0.90
addListenerFunction · 0.90
delListenerFunction · 0.90

Calls 3

sizeFunction · 0.90
collIsEmptyFunction · 0.90
mapSetFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…