effect-io-ai

Package: effect
Module: Graph

Graph.nodes

Creates an iterator over all node indices in the graph.

Details

The iterator produces node indices in the order they were added to the graph. This provides access to all nodes regardless of connectivity.

Example (Iterating all nodes)

import { Graph } from "effect"

const graph = Graph.directed<string, number>((mutable) => {
  const a = Graph.addNode(mutable, "A")
  const b = Graph.addNode(mutable, "B")
  const c = Graph.addNode(mutable, "C")
  Graph.addEdge(mutable, a, b, 1)
})

const indices = Array.from(Graph.indices(Graph.nodes(graph)))
console.log(indices) // [0, 1, 2]

Signature

declare const nodes: <N, E, T extends Kind = "directed">(graph: Graph<N, E, T> | MutableGraph<N, E, T>) => NodeWalker<N>

Source

Since v3.18.0