effect-io-ai

Package: effect
Module: Graph

Graph.getEdge

Gets the edge data associated with an edge index safely, if it exists.

Example (Getting edge data)

import { Graph } from "effect"

const graph = Graph.mutate(Graph.directed<string, number>(), (mutable) => {
  const nodeA = Graph.addNode(mutable, "Node A")
  const nodeB = Graph.addNode(mutable, "Node B")
  Graph.addEdge(mutable, nodeA, nodeB, 42)
})

const edgeIndex = 0
const edgeData = Graph.getEdge(graph, edgeIndex)

if (edgeData._tag === "Some") {
  console.log(edgeData.value.data) // 42
  console.log(edgeData.value.source) // 0
  console.log(edgeData.value.target) // 1
}

Signature

declare const getEdge: { (edgeIndex: EdgeIndex): <N, E, T extends Kind = "directed">(graph: Graph<N, E, T> | MutableGraph<N, E, T>) => Option.Option<Edge<E>>; <N, E, T extends Kind = "directed">(graph: Graph<N, E, T> | MutableGraph<N, E, T>, edgeIndex: EdgeIndex): Option.Option<Edge<E>>; }

Source

Since v3.18.0