Skip to content

Commit 90873fc

Browse files
Add a toMap function to unwrap a Graph (#18)
1 parent d100d7d commit 90873fc

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Breaking changes:
1919

2020
New features:
2121
- Added `Foldable` and `Traversable` instances for `Graph` (#16 by @MaybeJustJames)
22+
- Added `toMap` to unwrap `Graph` (#18)
2223

2324
Bugfixes:
2425

src/Data/Graph.purs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ module Data.Graph
44
( Graph
55
, unfoldGraph
66
, fromMap
7+
, toMap
78
, vertices
89
, lookup
910
, outEdges
@@ -62,6 +63,11 @@ unfoldGraph ks label edges =
6263
fromMap :: forall k v. Map k (Tuple v (List k)) -> Graph k v
6364
fromMap = Graph
6465

66+
-- | Create a `Map` which maps vertices to their labels and
67+
-- | outgoing edges from a `Graph`.
68+
toMap :: forall k v. Graph k v -> Map k (Tuple v (List k))
69+
toMap (Graph g) = g
70+
6571
-- | List all vertices in a graph.
6672
vertices :: forall k v. Graph k v -> List v
6773
vertices (Graph g) = map fst (M.values g)

0 commit comments

Comments
 (0)