<N, E, T extends Kind = "directed">(
mutable: MutableGraph<N, E, T>,
f: (data: N) => N
): voidTransforms every node's data in a mutable graph in place using the provided mapping function.
Details
Node indices and edges are preserved; only the stored node data is replaced.
Example (Mapping node data)
import { Graph } from "effect"
const graph = Graph.directed<string, number>((mutable) => {
Graph.addNode(mutable, "node a")
Graph.addNode(mutable, "node b")
Graph.addNode(mutable, "node c")
Graph.mapNodes(mutable, (data) => data.toUpperCase())
})
const nodeData = Graph.getNode(graph, 0)
console.log(nodeData) // Option.some("NODE A")export const const mapNodes: <
N,
E,
T extends Kind = "directed"
>(
mutable: MutableGraph<N, E, T>,
f: (data: N) => N
) => void
Transforms every node's data in a mutable graph in place using the provided
mapping function.
Details
Node indices and edges are preserved; only the stored node data is replaced.
Example (Mapping node data)
import { Graph } from "effect"
const graph = Graph.directed<string, number>((mutable) => {
Graph.addNode(mutable, "node a")
Graph.addNode(mutable, "node b")
Graph.addNode(mutable, "node c")
Graph.mapNodes(mutable, (data) => data.toUpperCase())
})
const nodeData = Graph.getNode(graph, 0)
console.log(nodeData) // Option.some("NODE A")
mapNodes = <function (type parameter) N in <N, E, T extends Kind = "directed">(mutable: MutableGraph<N, E, T>, f: (data: N) => N): voidN, function (type parameter) E in <N, E, T extends Kind = "directed">(mutable: MutableGraph<N, E, T>, f: (data: N) => N): voidE, function (type parameter) T in <N, E, T extends Kind = "directed">(mutable: MutableGraph<N, E, T>, f: (data: N) => N): voidT extends type Kind = "directed" | "undirected"Graph type for distinguishing directed and undirected graphs.
When to use
Use when writing graph-polymorphic types or helpers that need to preserve
whether a graph is directed or undirected.
Kind = "directed">(
mutable: MutableGraph<N, E, T>(parameter) mutable: {
type: T;
mutable: true;
nodes: Map<NodeIndex, N>;
edges: Map<EdgeIndex, Edge<E>>;
adjacency: Map<NodeIndex, Array<EdgeIndex>>;
reverseAdjacency: Map<NodeIndex, Array<EdgeIndex>>;
nextNodeIndex: NodeIndex;
nextEdgeIndex: EdgeIndex;
acyclic: Option.Option<boolean>;
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; <…;
toString: () => string;
toJSON: () => unknown;
}
mutable: interface MutableGraph<out N, out E, T extends Kind = "directed">Mutable graph interface.
When to use
Use when adding, removing, or updating nodes and edges inside a graph
mutation scope.
MutableGraph<function (type parameter) N in <N, E, T extends Kind = "directed">(mutable: MutableGraph<N, E, T>, f: (data: N) => N): voidN, function (type parameter) E in <N, E, T extends Kind = "directed">(mutable: MutableGraph<N, E, T>, f: (data: N) => N): voidE, function (type parameter) T in <N, E, T extends Kind = "directed">(mutable: MutableGraph<N, E, T>, f: (data: N) => N): voidT>,
f: (data: N) => Nf: (data: Ndata: function (type parameter) N in <N, E, T extends Kind = "directed">(mutable: MutableGraph<N, E, T>, f: (data: N) => N): voidN) => function (type parameter) N in <N, E, T extends Kind = "directed">(mutable: MutableGraph<N, E, T>, f: (data: N) => N): voidN
): void => {
// Transform existing node data in place
for (const [const index: numberindex, const data: Ndata] of mutable: MutableGraph<N, E, T>(parameter) mutable: {
type: T;
mutable: true;
nodes: Map<NodeIndex, N>;
edges: Map<EdgeIndex, Edge<E>>;
adjacency: Map<NodeIndex, Array<EdgeIndex>>;
reverseAdjacency: Map<NodeIndex, Array<EdgeIndex>>;
nextNodeIndex: NodeIndex;
nextEdgeIndex: EdgeIndex;
acyclic: Option.Option<boolean>;
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; <…;
toString: () => string;
toJSON: () => unknown;
}
mutable.Proto<N, E>.nodes: Map<NodeIndex, N>nodes) {
const const newData: NnewData = f: (data: N) => Nf(const data: Ndata)
mutable: MutableGraph<N, E, T>(parameter) mutable: {
type: T;
mutable: true;
nodes: Map<NodeIndex, N>;
edges: Map<EdgeIndex, Edge<E>>;
adjacency: Map<NodeIndex, Array<EdgeIndex>>;
reverseAdjacency: Map<NodeIndex, Array<EdgeIndex>>;
nextNodeIndex: NodeIndex;
nextEdgeIndex: EdgeIndex;
acyclic: Option.Option<boolean>;
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; <…;
toString: () => string;
toJSON: () => unknown;
}
mutable.Proto<N, E>.nodes: Map<NodeIndex, N>nodes.Map<number, N>.set(key: number, value: N): Map<number, N>Adds a new element with a specified key and value to the Map. If an element with the same key already exists, the element will be updated.
set(const index: numberindex, const newData: NnewData)
}
}