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

Function filterNodes

packages/effect/src/Graph.ts:2473–2491  ·  view source on GitHub ↗
(
  mutable: MutableGraph<N, E, T>,
  predicate: (data: N) => boolean
)

Source from the content-addressed store, hash-verified

2471 * @since 3.18.0
2472 */
2473export const filterNodes = <N, E, T extends Kind = "directed">(
2474 mutable: MutableGraph<N, E, T>,
2475 predicate: (data: N) => boolean
2476): void => {
2477 const impl = getMutableImplForMutation(mutable)
2478 const remove: Array<NodeIndex> = []
2479
2480 internal.withTransformation(mutable, () => {
2481 // Identify nodes to remove
2482 for (const [index, data] of impl.nodes) {
2483 if (!predicate(data)) {
2484 remove.push(index)
2485 }
2486 }
2487 })
2488
2489 // Remove filtered out nodes (this also removes connected edges)
2490 removeNodes(mutable, remove)
2491}
2492
2493/**
2494 * Filters edges by removing those that don't match the predicate.

Callers

nothing calls this directly

Calls 4

predicateFunction · 0.85
removeNodesFunction · 0.85
pushMethod · 0.65

Tested by

no test coverage detected