( mutable: MutableGraph<N, E, T>, f: (data: E) => Option.Option<E> )
| 2410 | * @since 3.18.0 |
| 2411 | */ |
| 2412 | export const filterMapEdges = <N, E, T extends Kind = "directed">( |
| 2413 | mutable: MutableGraph<N, E, T>, |
| 2414 | f: (data: E) => Option.Option<E> |
| 2415 | ): void => { |
| 2416 | const impl = getMutableImplForMutation(mutable) |
| 2417 | const remove: Array<EdgeIndex> = [] |
| 2418 | internal.withTransformation(mutable, () => { |
| 2419 | // First pass: identify edges to remove and transform data for edges to keep |
| 2420 | for (const [index, edgeData] of impl.edges) { |
| 2421 | const result = f(edgeData.data) |
| 2422 | if (Option.isSome(result)) { |
| 2423 | // Transform edge data |
| 2424 | impl.edges.set(index, { |
| 2425 | source: edgeData.source, |
| 2426 | target: edgeData.target, |
| 2427 | data: result.value |
| 2428 | }) |
| 2429 | } else { |
| 2430 | // Mark for removal |
| 2431 | remove.push(index) |
| 2432 | } |
| 2433 | } |
| 2434 | }) |
| 2435 | |
| 2436 | // Second pass: remove filtered out edges |
| 2437 | removeEdges(mutable, remove) |
| 2438 | } |
| 2439 | |
| 2440 | /** |
| 2441 | * Filters nodes by removing those that don't match the predicate. |
nothing calls this directly
no test coverage detected