yog

Yog - A comprehensive graph algorithm library for Gleam.

Provides efficient implementations of classic graph algorithms with a clean, functional API.

Quick Start

import yog.{type Graph}
import yog/model.{Directed}
import yog/pathfinding
import gleam/int

pub fn main() {
  let graph =
    model.new(Directed)
    |> model.add_node(1, "Start")
    |> model.add_node(2, "Middle")
    |> model.add_node(3, "End")
    |> model.add_edge(from: 1, to: 2, with: 5)
    |> model.add_edge(from: 2, to: 3, with: 3)
    |> model.add_edge(from: 1, to: 3, with: 10)

  case pathfinding.shortest_path(
    in: graph,
    from: 1,
    to: 3,
    with_zero: 0,
    with_add: int.add,
    with_compare: int.compare
  ) {
    Some(path) -> {
      // Path(nodes: [1, 2, 3], total_weight: 8)
      io.println("Shortest path found!")
    }
    None -> io.println("No path exists")
  }
}

Modules

Core

Algorithms

Transformations

Features

Types

pub type Graph(node_data, edge_data) =
  model.Graph(node_data, edge_data)
pub type GraphType =
  model.GraphType
pub type NodeId =
  Int
Search Document