( mutable: MutableGraph<N, E, T>, f: (data: E) => Option.Option<E> )
| 2082 | * @since 3.18.0 |
| 2083 | */ |
| 2084 | export const filterMapEdges = <N, E, T extends Kind = "directed">( |
| 2085 | mutable: MutableGraph<N, E, T>, |
| 2086 | f: (data: E) => Option.Option<E> |
| 2087 | ): void => { |
| 2088 | assertMutable(mutable) |
| 2089 | const impl = graphImpl(mutable) |
| 2090 | |
| 2091 | const edgesToRemove: Array<EdgeIndex> = [] |
| 2092 | |
| 2093 | // First pass: identify edges to remove and transform data for edges to keep |
| 2094 | for (const [index, edgeData] of impl.edges) { |
| 2095 | const result = f(edgeData.data) |
| 2096 | if (Option.isSome(result)) { |
| 2097 | // Transform edge data |
| 2098 | impl.edges.set( |
| 2099 | index, |
| 2100 | new Edge({ |
| 2101 | ...edgeData, |
| 2102 | data: result.value |
| 2103 | }) |
| 2104 | ) |
| 2105 | } else { |
| 2106 | // Mark for removal |
| 2107 | edgesToRemove.push(index) |
| 2108 | } |
| 2109 | } |
| 2110 | |
| 2111 | // Second pass: remove filtered out edges |
| 2112 | for (const edgeIndex of edgesToRemove) { |
| 2113 | removeEdge(mutable, edgeIndex) |
| 2114 | } |
| 2115 | } |
| 2116 | |
| 2117 | /** |
| 2118 | * Filters nodes by removing those that don't match the predicate. |
nothing calls this directly
no test coverage detected