EdgeWalker<E>Type alias for edge iteration using Walker. EdgeWalker is represented as Walker<EdgeIndex, Edge>.
When to use
Use to type helpers or parameters that consume edge iterators returned by
Graph APIs, where each item is keyed by an EdgeIndex and carries the
full Edge.
export type type EdgeWalker<E> = Walker<
number,
Edge<E>
>
Type alias for edge iteration using Walker.
EdgeWalker is represented as Walker<EdgeIndex, Edge>.
When to use
Use to type helpers or parameters that consume edge iterators returned by
Graph APIs, where each item is keyed by an EdgeIndex and carries the
full Edge.
EdgeWalker<function (type parameter) E in type EdgeWalker<E>E> = class Walker<T, N>class Walker {
visit: <U>(f: (index: T, data: N) => U) => Iterable<U>;
}
Represents an iterable wrapper used by graph traversal and listing APIs.
Details
A Walker yields [index, data] pairs lazily and can be viewed as just the
indices, just the values, or mapped entries with indices, values,
entries, and visit.
Example (Working with node walkers)
import { Graph } from "effect"
const graph = Graph.directed<string, number>((mutable) => {
const a = Graph.addNode(mutable, "A")
const b = Graph.addNode(mutable, "B")
Graph.addEdge(mutable, a, b, 1)
})
// Both traversal and element iterators return NodeWalker
const dfsNodes: Graph.NodeWalker<string> = Graph.dfs(graph, { start: [0] })
const allNodes: Graph.NodeWalker<string> = Graph.nodes(graph)
// Common interface for working with node iterables
function processNodes<N>(nodeIterable: Graph.NodeWalker<N>): Array<number> {
return Array.from(Graph.indices(nodeIterable))
}
// Access node data using values() or entries()
const nodeData = Array.from(Graph.values(dfsNodes)) // ["A", "B"]
const nodeEntries = Array.from(Graph.entries(allNodes)) // [[0, "A"], [1, "B"]]
Walker<type EdgeIndex = numberEdge index for edge identification using plain numbers.
When to use
Use when you need to keep the identifier for a graph edge so you can later
read, update, remove, or compare that edge.
Gotchas
An EdgeIndex is an identifier, not an array offset. Removed edge
identifiers are not reused.
EdgeIndex, class Edge<E>class Edge {
source: number;
target: number;
data: E;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
Represents edge data containing source, target, and user data.
When to use
Use as the graph edge value that carries source node, target node, and stored
edge data together.
Edge<function (type parameter) E in type EdgeWalker<E>E>>