$ open source · GPL-3.0 — need a commercial license? imqueue.com →

Graph.forEach() method

Visits every vertex once, depth first.

Signature:

forEach(callback: GraphForeachCallback<T>): Graph<T>;

Parameters

Parameter

Type

Description

callback

GraphForeachCallback<T>

Called once per vertex.

Returns:

Graph<T>

This graph, for chaining.

Remarks

Walks from each vertex in turn, sharing one visited set across all of them — so the callback sees each vertex exactly once no matter how many paths reach it, and a disconnected part of the graph is covered too. A callback returning false prunes that branch; the traversal moves on to the next vertex rather than stopping.