Created
March 17, 2014 15:45
-
-
Save micha/9601749 to your computer and use it in GitHub Desktop.
Datomic transactor function that works like Clojure's `swap!` function.
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
{:db/id #db/id[:db.part/db] | |
:db/doc "Works like clojure.core/swap!, basically." | |
:db/ident :swap! | |
:db/fn #db/fn {:lang "clojure" | |
:params [db id k expr args] | |
:code "(let [f (if-not (string? expr) | |
(resolve expr) | |
(eval (read-string expr))) | |
e (datomic.api/entity db id) | |
v (apply f (concat [(get e k 0)] args))] | |
[[:db/add id k v]])"}} |
Author
micha
commented
May 17, 2014
Possibly want eval
on line 7 instead of resolve
?
Perhaps to be able to do this:
@(d/transact conn [[:swap! 123456 :foo/count '(fn [x y] (+ x y)) [42]]])
I wonder if that would work?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment