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

Function filterNodes

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

Source from the content-addressed store, hash-verified

2140 * @since 3.18.0
2141 */
2142export const filterNodes = <N, E, T extends Kind = "directed">(
2143 mutable: MutableGraph<N, E, T>,
2144 predicate: (data: N) => boolean
2145): void => {
2146 assertMutable(mutable)
2147 const impl = graphImpl(mutable)
2148
2149 const nodesToRemove: Array<NodeIndex> = []
2150
2151 // Identify nodes to remove
2152 for (const [index, data] of impl.nodes) {
2153 if (!predicate(data)) {
2154 nodesToRemove.push(index)
2155 }
2156 }
2157
2158 // Remove filtered out nodes (this also removes connected edges)
2159 for (const nodeIndex of nodesToRemove) {
2160 removeNode(mutable, nodeIndex)
2161 }
2162}
2163
2164/**
2165 * Filters edges by removing those that don't match the predicate.

Callers

nothing calls this directly

Calls 5

assertMutableFunction · 0.85
graphImplFunction · 0.85
predicateFunction · 0.85
removeNodeFunction · 0.85
pushMethod · 0.80

Tested by

no test coverage detected