Created
October 2, 2013 16:47
-
-
Save arrdem/6796711 to your computer and use it in GitHub Desktop.
A toy directed graph imp'l with nonworking core.typed annotations.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns name.arrdem.bored.typed-graph | |
(:require [clojure.core.typed :as type]) | |
(:refer-clojure :exclude [hash])) | |
;;------------------------------------------------------------------------------ | |
;; Simple graph API | |
(def Node clojure.lang.Keyword) | |
(def Graph (type/Map Node (type/Seq Node))) | |
(def children | |
(type/fn> :- (type/Set Node) | |
[graph :- Graph | |
node :- Node] | |
(get graph node))) | |
(def add-node | |
(type/fn> :- Graph [graph :- Graph | |
node :- Node] | |
(assoc graph node #{}))) | |
(def add-edge | |
(typed/fn> :- Graph [graph :- Graph | |
node-a :- Node | |
node-b :- Node] | |
(update-in graph [node-a] | |
conj node-b))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment