Hyperlinkv0.8.0-beta.28

Graph

Graph.directedconsteffect/Graph.ts:396
<N, E>(
  mutate?: (mutable: MutableDirectedGraph<N, E>) => void
): DirectedGraph<N, E>

Creates a directed graph, optionally with initial mutations.

Example (Creating a directed graph)

import { Graph } from "effect"

// Directed graph with initial nodes and edges
const graph = Graph.directed<string, string>((mutable) => {
  const a = Graph.addNode(mutable, "A")
  const b = Graph.addNode(mutable, "B")
  const c = Graph.addNode(mutable, "C")
  Graph.addEdge(mutable, a, b, "A->B")
  Graph.addEdge(mutable, b, c, "B->C")
})
constructors
Source effect/Graph.ts:39620 lines
export const directed = <N, E>(mutate?: (mutable: MutableDirectedGraph<N, E>) => void): DirectedGraph<N, E> => {
  const graph: Mutable<DirectedGraph<N, E>> = Object.create(ProtoGraph)
  graph.type = "directed"
  graph.nodes = new Map()
  graph.edges = new Map()
  graph.adjacency = new Map()
  graph.reverseAdjacency = new Map()
  graph.nextNodeIndex = 0
  graph.nextEdgeIndex = 0
  graph.acyclic = Option.some(true)
  graph.mutable = false

  if (mutate) {
    const mutable = beginMutation(graph as DirectedGraph<N, E>)
    mutate(mutable as MutableDirectedGraph<N, E>)
    return endMutation(mutable)
  }

  return graph
}