( mutable: MutableGraph<N, E, T>, f: (data: N) => Option.Option<N> )
| 2350 | * @since 3.18.0 |
| 2351 | */ |
| 2352 | export const filterMapNodes = <N, E, T extends Kind = "directed">( |
| 2353 | mutable: MutableGraph<N, E, T>, |
| 2354 | f: (data: N) => Option.Option<N> |
| 2355 | ): void => { |
| 2356 | const impl = getMutableImplForMutation(mutable) |
| 2357 | const remove: Array<NodeIndex> = [] |
| 2358 | internal.withTransformation(mutable, () => { |
| 2359 | // First pass: identify nodes to remove and transform data for nodes to keep |
| 2360 | for (const [index, data] of impl.nodes) { |
| 2361 | const result = f(data) |
| 2362 | if (Option.isSome(result)) { |
| 2363 | // Transform node data |
| 2364 | impl.nodes.set(index, result.value) |
| 2365 | } else { |
| 2366 | // Mark for removal |
| 2367 | remove.push(index) |
| 2368 | } |
| 2369 | } |
| 2370 | }) |
| 2371 | |
| 2372 | // Second pass: remove filtered out nodes and their edges |
| 2373 | removeNodes(mutable, remove) |
| 2374 | } |
| 2375 | |
| 2376 | /** |
| 2377 | * Filters and optionally transforms edges in a mutable graph using a predicate function. |
nothing calls this directly
no test coverage detected