( node: Node<Path, Leaf>, path: Path[], ensureLeaf?: () => Leaf, pruneLeaf?: (leaf: Leaf) => 1 | 0 | void, p = 0, )
| 144 | |
| 145 | export type Node<Path, Leaf> = Map<Path, Node<Path, Leaf> | Leaf>; |
| 146 | export 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 | ); |
no test coverage detected
searching dependent graphs…