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

Function filterMapNodes

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

Source from the content-addressed store, hash-verified

2350 * @since 3.18.0
2351 */
2352export 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.

Callers

nothing calls this directly

Calls 5

removeNodesFunction · 0.85
setMethod · 0.65
pushMethod · 0.65
fFunction · 0.50

Tested by

no test coverage detected