noordstar/elm-graph/1.0.0

Graph

Graph

The Graph type helps define relational data.

type Graph vertex edge

A graph is a large data type containing various data points that are linked to each other.

A Graph consists of data points (called vertices) that can be connected to each other.

type Vertex vertex

A Vertex is a data point within the graph. You can store various bits of content in it.

vLabel : Vertex vertex -> vertex

Finds the label of a vertex.

Vertices can connect to each other using edges. A connection has a one-way direction and a label. There can not be more than two edges between two vertices (one for each direction).

type Edge vertex edge

An edge is a relation between two vertices. For example, one person can have a relationship with another person - and you can use a custom edge type to reveal more about the type of relationship.

eLabel : Edge vertex edge -> edge

Finds the label of an edge.

origin : Edge vertex edge -> Vertex vertex

Get the vertex that an edge starts from.

destination : Edge vertex edge -> Vertex vertex

Get the destination that an edge points to.

Build

empty : Graph vertex edge

A new and empty graph containing no vertices.

singleton : vertex -> ( Vertex vertex, Graph vertex edge )

Create a graph with a single vertex in it.

insertV : vertex -> Graph vertex edge -> ( Vertex vertex, Graph vertex edge )

Insert a new vertex into the graph.

{ content : edge
, from : Vertex vertex
, to : Vertex vertex
}
-> Graph vertex edge
-> Graph vertex edge

Insert a new edge into the graph. If the edge already exists, it is overwritten.

{ from : Vertex vertex
, to : Vertex vertex
}
-> (Maybe edge -> Maybe edge)
-> Graph vertex edge
-> Graph vertex edge

Check whether an edge already exists, and update it according to your needs.

{ from : Vertex vertex
, to : Vertex vertex
}
-> Graph vertex edge
-> Graph vertex edge

Remove an edge from the graph.

removeV : Vertex vertex -> Graph vertex edge -> Graph vertex edge

Remove a vertex from the graph.

Query

isEmpty : Graph vertex edge -> Bool

Checks whether a graph is empty.

{ from : Vertex vertex
, to : Vertex vertex
}
-> Graph vertex edge
-> Maybe (Edge vertex edge)

Get an edge between two vertices, if it exists.

sizeE : Graph vertex edge -> Int

Determines the number of edges in a graph.

sizeV : Graph vertex edge -> Int

Determines the number of vertices in a graph.

Lists

v : Graph vertex edge -> List (Vertex vertex)

Get a list of all vertices.

e : Graph vertex edge -> List (Edge vertex edge)

Get a list of all edges

Transform

(Vertex vertex1 -> vertex2)
-> Graph vertex1 edge
-> Graph vertex2 edge

Map all vertex labels to a new value. This function cannot change the structure of the graph, but it can use the structure of the graph to remap the labels.

mapE : (edge1 -> edge2) -> Graph vertex edge1 -> Graph vertex edge2

Map all edge labels to a new value. Note that this function is completely blind to the location of each edge.

foldl : (Vertex vertex -> a -> a) -> a -> Graph vertex edge -> a

Fold over the vertices in the graph from oldest to newest added vertex.

foldr : (Vertex vertex -> a -> a) -> a -> Graph vertex edge -> a

Fold over the vertices in the graph from newest to oldest added vertex.

Traverse

degree : Vertex vertex -> Graph vertex edge -> Int

Get the number of outgoing edges for a given vertex.

pointsTo : Vertex vertex -> Graph vertex edge -> List ( edge, Vertex vertex )

Get all the edges that start from a given vertex.