MCPcopy Create free account
hub / github.com/Effect-TS/effect / filterMapEdges

Function filterMapEdges

packages/effect/src/Graph.ts:2412–2438  ·  view source on GitHub ↗
(
  mutable: MutableGraph<N, E, T>,
  f: (data: E) => Option.Option<E>
)

Source from the content-addressed store, hash-verified

2410 * @since 3.18.0
2411 */
2412export 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.

Callers

nothing calls this directly

Calls 5

removeEdgesFunction · 0.85
setMethod · 0.65
pushMethod · 0.65
fFunction · 0.50

Tested by

no test coverage detected