Hyperlinkv0.8.0-beta.28

Graph

Graph.predecessorsconsteffect/Graph.ts:1889
(nodeIndex: NodeIndex): <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
): Array<NodeIndex>

Returns the incoming neighbor node indices for a node in a directed graph.

When to use

Use when you need the nodes that reach a node by following incoming edges in a directed graph.

Gotchas

Throws a GraphError when used with an undirected graph.

Source effect/Graph.ts:188917 lines
export const predecessors: {
  (
    nodeIndex: NodeIndex
  ): <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
  ): Array<NodeIndex>
} = dual(2, <N, E, T extends Kind = "directed">(
  graph: Graph<N, E, T> | MutableGraph<N, E, T>,
  nodeIndex: NodeIndex
): Array<NodeIndex> => {
  if (graph.type === "undirected") {
    throw new GraphError({ message: "Cannot get predecessors of undirected graph" })
  }
  return getDirectedNeighbors(graph as Graph<N, E, "directed"> | MutableGraph<N, E, "directed">, nodeIndex, "incoming")
})