<N, E, T extends Kind = "directed">(
mutable: MutableGraph<N, E, T>,
index: NodeIndex,
f: (data: N) => N
): voidUpdates a single node's data by applying a transformation function.
Example (Updating node data)
import { Graph } from "effect"
const graph = Graph.directed<string, number>((mutable) => {
Graph.addNode(mutable, "Node A")
Graph.addNode(mutable, "Node B")
Graph.updateNode(mutable, 0, (data) => data.toUpperCase())
})
const nodeData = Graph.getNode(graph, 0)
console.log(nodeData) // Option.some("NODE A")export const const updateNode: <
N,
E,
T extends Kind = "directed"
>(
mutable: MutableGraph<N, E, T>,
index: NodeIndex,
f: (data: N) => N
) => void
Updates a single node's data by applying a transformation function.
Example (Updating node data)
import { Graph } from "effect"
const graph = Graph.directed<string, number>((mutable) => {
Graph.addNode(mutable, "Node A")
Graph.addNode(mutable, "Node B")
Graph.updateNode(mutable, 0, (data) => data.toUpperCase())
})
const nodeData = Graph.getNode(graph, 0)
console.log(nodeData) // Option.some("NODE A")
updateNode = <function (type parameter) N in <N, E, T extends Kind = "directed">(mutable: MutableGraph<N, E, T>, index: NodeIndex, f: (data: N) => N): voidN, function (type parameter) E in <N, E, T extends Kind = "directed">(mutable: MutableGraph<N, E, T>, index: NodeIndex, f: (data: N) => N): voidE, function (type parameter) T in <N, E, T extends Kind = "directed">(mutable: MutableGraph<N, E, T>, index: NodeIndex, 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>, index: NodeIndex, f: (data: N) => N): voidN, function (type parameter) E in <N, E, T extends Kind = "directed">(mutable: MutableGraph<N, E, T>, index: NodeIndex, f: (data: N) => N): voidE, function (type parameter) T in <N, E, T extends Kind = "directed">(mutable: MutableGraph<N, E, T>, index: NodeIndex, f: (data: N) => N): voidT>,
index: NodeIndexindex: type NodeIndex = numberNode index for node identification using plain numbers.
When to use
Use when storing or passing the stable identifier of a graph node between
Graph operations.
Details
addNode allocates node identifiers from the graph's next node index.
Gotchas
A NodeIndex is an identifier, not an array offset. Removed node identifiers
are not reused.
NodeIndex,
f: (data: N) => Nf: (data: Ndata: function (type parameter) N in <N, E, T extends Kind = "directed">(mutable: MutableGraph<N, E, T>, index: NodeIndex, f: (data: N) => N): voidN) => function (type parameter) N in <N, E, T extends Kind = "directed">(mutable: MutableGraph<N, E, T>, index: NodeIndex, f: (data: N) => N): voidN
): void => {
if (!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>.has(key: number): booleanhas(index: NodeIndexindex)) {
return
}
const const currentData: NonNullable<N>currentData = 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>.get(key: number): N | undefinedReturns a specified element from the Map object. If the value that is associated to the provided key is an object, then you will get a reference to that object and any change made to that object will effectively modify it inside the Map.
get(index: NodeIndexindex)!
const const newData: NnewData = f: (data: N) => Nf(const currentData: NonNullable<N>currentData)
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(index: NodeIndexindex, const newData: NnewData)
}