effect-io-ai

Package: effect
Module: Graph

Graph.neighborsDirected

Gets directed neighbors of a node in a specific direction.

When to use

Use when maintaining existing code that already passes an explicit traversal direction. New code should prefer successors or predecessors.

Gotchas

Throws a GraphError when used with an undirected graph.

Example (Traversing directed neighbors)

import { Graph } from "effect"

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

const nodeA = 0
const nodeB = 1

// Get outgoing neighbors (nodes that nodeA points to)
const outgoing = Graph.neighborsDirected(graph, nodeA, "outgoing")

// Get incoming neighbors (nodes that point to nodeB)
const incoming = Graph.neighborsDirected(graph, nodeB, "incoming")

See

Signature

declare const neighborsDirected: { (nodeIndex: NodeIndex, direction: Direction): <N, E>(graph: Graph<N, E, "directed"> | MutableGraph<N, E, "directed">) => Array<NodeIndex>; <N, E>(graph: Graph<N, E, "directed"> | MutableGraph<N, E, "directed">, nodeIndex: NodeIndex, direction: Direction): Array<NodeIndex>; }

Source

Since v3.18.0