Skip to content

Instantly share code, notes, and snippets.

@duckyuck
Last active December 26, 2015 21:59
Show Gist options
  • Save duckyuck/7219586 to your computer and use it in GitHub Desktop.
Save duckyuck/7219586 to your computer and use it in GitHub Desktop.
{: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