Skip to content

Instantly share code, notes, and snippets.

@arohner
Created May 25, 2015 16:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arohner/d7a6bb057824c224b5b3 to your computer and use it in GitHub Desktop.
Save arohner/d7a6bb057824c224b5b3 to your computer and use it in GitHub Desktop.
rudimentary core.typed datomic annotations
;;; Extremely incomplete type annotations for Datomic.
(ns foo.util.type.datomic
(:require [clojure.core.typed :as t]
[datomic.api :as d])
(:import (datomic Connection
Database)
(datomic.db DbId)
(java.util Date UUID)))
(t/ann ^:no-check datomic.api/tempid [t/Keyword -> datomic.db.DbId])
(t/defalias TxVal (t/U DbId t/AnyInteger String Boolean BigInteger Double BigDecimal Date UUID (Array byte)))
(t/defalias TxAttr t/Keyword)
(t/defalias TxVec (t/HVec [t/Keyword TxAttr TxVal])) ;; [:db/add e a v]
(t/defalias TxMap (t/Map TxAttr TxVal))
(t/defalias TxDatom (t/U TxVec TxMap))
(t/defalias TxData (t/Vec TxDatom))
(t/ann ^:no-check datomic.api/db [Connection -> Database])
(t/defalias TxResult (t/HMap :mandatory {}))
(t/ann ^:no-check datomic.api/transact [Connection TxData -> (t/Future TxResult)])
(t/defalias PullPattern (t/Vec t/Any))
(t/ann ^:no-check datomic.api/pull [Database PullPattern Long -> (t/Map TxAttr TxVal)])
(t/defalias Query (t/Vec t/Any))
(t/ann ^:no-check datomic.api/q [Query Database TxVal * -> t/Any])
@marklar
Copy link

marklar commented May 26, 2015

Thank you!

In case it's of any interest, I've extended it ever so slightly.

;; In `ns` statement, added the importing of `datomic.Entity`.
...
  (:import (datomic Connection
                    Database
                    Entity)   ;; <= added
           (datomic.db DbId)
           (java.util Date UUID)))
...

;; Added these two annotations.
(t/ann ^:no-check datomic.api/connect [String -> Connection])
(t/ann ^:no-check datomic.api/entity  [Database Query -> Entity])

Thanks again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment