Last active
December 26, 2015 21:59
-
-
Save duckyuck/7219586 to your computer and use it in GitHub Desktop.
Working version of code from http://augustl.com/blog/2013/ordering_cardinality_many_in_datomic/
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/user] | |
:db/ident :reset-position-in-scope | |
:db/doc "Goes through existing positions and sequentializes them" | |
:db/fn #db/fn {:lang "clojure" | |
:params [db scope-id scope-attr retracted-eid sorted-attr] | |
:code (let [children (scope-attr (datomic.api/entity db scope-id)) | |
sorted-children-eids (map :db/id (sort-by sorted-attr children)) | |
without-retracted-eids (filter (partial not= retracted-eid) sorted-children-eids)] | |
(map-indexed | |
(fn [idx entity-id] | |
[:db/add entity-id sorted-attr idx]) | |
without-retracted-eids))}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment