Hyperlinkv0.8.0-beta.28

Graph

Graph.mutateconsteffect/Graph.ts:564
<N, E, T extends Kind = "directed">(
  f: (mutable: MutableGraph<N, E, T>) => void
): (graph: Graph<N, E, T>) => Graph<N, E, T>
<N, E, T extends Kind = "directed">(
  graph: Graph<N, E, T>,
  f: (mutable: MutableGraph<N, E, T>) => void
): Graph<N, E, T>

Performs scoped mutations on a graph, automatically managing the mutation lifecycle.

Example (Applying scoped mutations)

import { Graph } from "effect"

const graph = Graph.directed<string, number>()
const newGraph = Graph.mutate(graph, (mutable) => {
  const nodeA = Graph.addNode(mutable, "A")
  const nodeB = Graph.addNode(mutable, "B")
  Graph.addEdge(mutable, nodeA, nodeB, 1)
})

console.log(Graph.nodeCount(newGraph)) // 2
console.log(Graph.edgeCount(newGraph)) // 1
mutations
Source effect/Graph.ts:56416 lines
export const mutate: {
  <N, E, T extends Kind = "directed">(
    f: (mutable: MutableGraph<N, E, T>) => void
  ): (graph: Graph<N, E, T>) => Graph<N, E, T>
  <N, E, T extends Kind = "directed">(
    graph: Graph<N, E, T>,
    f: (mutable: MutableGraph<N, E, T>) => void
  ): Graph<N, E, T>
} = dual(2, <N, E, T extends Kind = "directed">(
  graph: Graph<N, E, T>,
  f: (mutable: MutableGraph<N, E, T>) => void
): Graph<N, E, T> => {
  const mutable = beginMutation(graph)
  f(mutable)
  return endMutation(mutable)
})