Hyperlinkv0.8.0-beta.28

Graph

Graph.updateNodeconsteffect/Graph.ts:941
<N, E, T extends Kind = "directed">(
  mutable: MutableGraph<N, E, T>,
  index: NodeIndex,
  f: (data: N) => N
): void

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

Example (Updating node data)

import { Graph } from "effect"

const graph = Graph.directed<string, number>((mutable) => {
  Graph.addNode(mutable, "Node A")
  Graph.addNode(mutable, "Node B")
  Graph.updateNode(mutable, 0, (data) => data.toUpperCase())
})

const nodeData = Graph.getNode(graph, 0)
console.log(nodeData) // Option.some("NODE A")
transforming
Source effect/Graph.ts:94113 lines
export const updateNode = <N, E, T extends Kind = "directed">(
  mutable: MutableGraph<N, E, T>,
  index: NodeIndex,
  f: (data: N) => N
): void => {
  if (!mutable.nodes.has(index)) {
    return
  }

  const currentData = mutable.nodes.get(index)!
  const newData = f(currentData)
  mutable.nodes.set(index, newData)
}