Hyperlinkv0.8.0-beta.28

Graph

Graph.getEdgeconsteffect/Graph.ts:1649
<E>(edgeIndex: EdgeIndex): <N, 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>>

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
}
getters
Source effect/Graph.ts:164912 lines
export const getEdge: {
  <E>(
    edgeIndex: EdgeIndex
  ): <N, 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>>
} = dual(2, <N, E, T extends Kind = "directed">(
  graph: Graph<N, E, T> | MutableGraph<N, E, T>,
  edgeIndex: EdgeIndex
): Option.Option<Edge<E>> => Option.fromUndefinedOr(graph.edges.get(edgeIndex)))