Hyperlinkv0.8.0-beta.28

Graph

Graph.updateEdgeconsteffect/Graph.ts:977
<N, E, T extends Kind = "directed">(
  mutable: MutableGraph<N, E, T>,
  edgeIndex: EdgeIndex,
  f: (data: E) => E
): void

Updates a single edge's data by applying a transformation function.

Example (Updating edge data)

import { Graph } from "effect"

const result = Graph.mutate(Graph.directed<string, number>(), (mutable) => {
  const nodeA = Graph.addNode(mutable, "Node A")
  const nodeB = Graph.addNode(mutable, "Node B")
  const edgeIndex = Graph.addEdge(mutable, nodeA, nodeB, 10)
  Graph.updateEdge(mutable, edgeIndex, (data) => data * 2)
})

const edgeData = Graph.getEdge(result, 0)
console.log(edgeData) // Option.some(new Graph.Edge({ source: 0, target: 1, data: 20 }))
mutations
Source effect/Graph.ts:97713 lines
export const updateEdge = <N, E, T extends Kind = "directed">(
  mutable: MutableGraph<N, E, T>,
  edgeIndex: EdgeIndex,
  f: (data: E) => E
): void => {
  if (!mutable.edges.has(edgeIndex)) {
    return
  }

  const currentEdge = mutable.edges.get(edgeIndex)!
  const newData = f(currentEdge.data)
  mutable.edges.set(edgeIndex, new Edge({ ...currentEdge, data: newData }))
}