gleaph/edge

Manipulate

update_relation

Types

Represents an edge between two nodes with an optional relation.

pub type Edge(relation_t) {
  Edge(from: Int, to: Int, relation: option.Option(relation_t))
}

Constructors

Values

pub fn update_relation(
  edge: Edge(relation_old_t),
  with modifier: fn(option.Option(relation_old_t)) -> option.Option(
    relation_new_t,
  ),
) -> Edge(relation_new_t)

Updates the relation of an edge.

Examples

import gleam/option

let edge = Edge(from: 0, to: 1, relation: option.Some(100))
let edge_updated = update_relation(edge, fn(rel_opt) {
  case rel_opt {
    option.Some(val) -> val + 11
    option.None -> option.None
  }
})
// edge_updated has relation 111.
Search Document