Skip to content

Commit f0ea70e

Browse files
committed
Update examples
1 parent 27dca23 commit f0ea70e

File tree

9 files changed

+29
-24
lines changed

9 files changed

+29
-24
lines changed

examples/city_distance_matrix.gleam

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,17 @@ pub fn main() {
3131
)
3232
{
3333
Ok(matrix) -> {
34-
// Matrix is Dict(NodeId, Dict(NodeId, Weight))
35-
dict.each(matrix, fn(from, rows) {
36-
dict.each(rows, fn(to, weight) {
37-
io.println(
38-
"From "
39-
<> int.to_string(from)
40-
<> " to "
41-
<> int.to_string(to)
42-
<> ": "
43-
<> int.to_string(weight),
44-
)
45-
})
34+
// Matrix is Dict(#(NodeId, NodeId), Weight)
35+
dict.each(matrix, fn(key, weight) {
36+
let #(from, to) = key
37+
io.println(
38+
"From "
39+
<> int.to_string(from)
40+
<> " to "
41+
<> int.to_string(to)
42+
<> ": "
43+
<> int.to_string(weight),
44+
)
4645
})
4746
}
4847
Error(_) -> io.println("Negative cycle detected!")

examples/graph_generation_showcase.gleam

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ pub fn main() {
8888
io.println("(Directed has edges in both directions)")
8989
}
9090

91-
fn print_graph_stats(name: String, graph: model.Graph(Nil, Int)) -> Nil {
91+
fn print_graph_stats(_name: String, graph: model.Graph(Nil, Int)) -> Nil {
9292
let node_count = model.all_nodes(graph) |> list_length()
9393
let edge_count = count_edges(graph)
9494

examples/job_assignment.gleam

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import gleam/int
22
import gleam/io
33
import gleam/list
4+
import gleam/option.{None, Some}
45
import yog/bipartite
56
import yog/model
67

examples/render_dot.gleam

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import gleam/option.{None, Some}
44
import yog/model
55
import yog/pathfinding
66
import yog/render
7+
import yog/transform
78

89
pub fn main() {
910
// Create a sample graph
@@ -20,7 +21,7 @@ pub fn main() {
2021
io.println("--- Basic DOT Output ---")
2122
let dot_basic =
2223
render.to_dot(
23-
graph |> model.map_edges(int.to_string),
24+
graph |> transform.map_edges(int.to_string),
2425
render.default_dot_options(),
2526
)
2627
io.println(dot_basic)
@@ -32,7 +33,7 @@ pub fn main() {
3233
let options =
3334
render.path_to_dot_options(path, render.default_dot_options())
3435
let dot_highlighted =
35-
render.to_dot(graph |> model.map_edges(int.to_string), options)
36+
render.to_dot(graph |> transform.map_edges(int.to_string), options)
3637
io.println(dot_highlighted)
3738
}
3839
None -> io.println("No path found")

examples/render_json.gleam

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import gleam/int
21
import gleam/io
32
import gleam/json
43
import yog/model

examples/render_mermaid.gleam

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import gleam/option.{None, Some}
44
import yog/model
55
import yog/pathfinding
66
import yog/render
7+
import yog/transform
78

89
pub fn main() {
910
// Create a sample graph
@@ -20,7 +21,7 @@ pub fn main() {
2021
io.println("--- Basic Mermaid Output ---")
2122
let mermaid_basic =
2223
render.to_mermaid(
23-
graph |> model.map_edges(int.to_string),
24+
graph |> transform.map_edges(int.to_string),
2425
render.default_options(),
2526
)
2627
io.println("```mermaid")
@@ -31,17 +32,18 @@ pub fn main() {
3132
io.println("\n--- Mermaid with Custom Labels & Highlighting ---")
3233
case pathfinding.shortest_path(graph, 1, 3, 0, int.add, int.compare) {
3334
Some(path) -> {
34-
let options =
35+
let base_options =
3536
render.MermaidOptions(
3637
node_label: fn(id, data) {
3738
data <> " (ID: " <> int.to_string(id) <> ")"
3839
},
3940
edge_label: fn(weight) { weight <> " km" },
40-
highlighted_nodes: Some(path.nodes),
41-
highlighted_edges: Some(render.path_to_edges(path)),
41+
highlighted_nodes: None,
42+
highlighted_edges: None,
4243
)
44+
let options = render.path_to_options(path, base_options)
4345
let mermaid_custom =
44-
render.to_mermaid(graph |> model.map_edges(int.to_string), options)
46+
render.to_mermaid(graph |> transform.map_edges(int.to_string), options)
4547
io.println("```mermaid")
4648
io.println(mermaid_custom)
4749
io.println("```")

examples/social_network_analysis.gleam

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import gleam/io
2+
import gleam/string
23
import yog/components
34
import yog/model.{Directed}
45

@@ -15,6 +16,6 @@ pub fn main() {
1516

1617
// Find groups of mutually connected users
1718
let communities = components.strongly_connected_components(social_graph)
18-
io.debug(communities)
19+
io.println(string.inspect(communities))
1920
// => [[1, 2, 3]] // All three users form a strongly connected community
2021
}

examples/task_ordering.gleam

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import gleam/dict
2-
import gleam/int
32
import gleam/io
43
import gleam/list
54
import gleam/string
@@ -40,7 +39,9 @@ pub fn main() {
4039
|> model.add_edge(from: prereq_id, to: step_id, with: Nil)
4140
})
4241

43-
case topological_sort.lexicographical_topological_sort(graph, int.compare) {
42+
case
43+
topological_sort.lexicographical_topological_sort(graph, string.compare)
44+
{
4445
Ok(order) -> {
4546
let task_order =
4647
order

src/examples

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/home/mafinar/repos/gleam/yog/examples

0 commit comments

Comments
 (0)