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

Function filterMapEdges

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

Source from the content-addressed store, hash-verified

2082 * @since 3.18.0
2083 */
2084export 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.

Callers

nothing calls this directly

Calls 6

assertMutableFunction · 0.85
graphImplFunction · 0.85
removeEdgeFunction · 0.85
pushMethod · 0.80
setMethod · 0.65
fFunction · 0.50

Tested by

no test coverage detected