Skip to content

Commit

Permalink
Add Clojure example code to readme
Browse files Browse the repository at this point in the history
  • Loading branch information
alandipert committed Jan 7, 2016
1 parent f0ef356 commit c9baece
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,17 @@ implementations like [Datomic's own][1] or [DataScript][2].
pets-db)
;;=> #{["George"] ["Francis"] ["Bob"]}

;; Find each owner, and how many pets each owns:
;; To find each owner and how many pets each owner owns, we could write Clojure code like this:

(reduce
(fn [m pet]
(reduce #(update %1 %2 (fnil + 0) 1) m (get pet :owners)))
{}
pets)
;;=> {"Peirce" 2, "Frege" 1, "De Morgan" 1}

;; I find that code hard to follow, which is why I made this library. Here's how
;; it could be done in Datalog:

(q '[:find ?owner (count ?pet)
:where
Expand Down

0 comments on commit c9baece

Please sign in to comment.