Advertisement
Guest User

Untitled

a guest
Jan 24th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. (ns test.core
  2. (:require [clojure.spec :as s]
  3. [clojure.spec.test :as stest]
  4. [clojure.test.check.generators :as gen]))
  5.  
  6. (s/def ::file-count nat-int?)
  7. (s/def ::operations (s/map-of keyword? pos-int?))
  8. (s/def ::time-total (s/and double? (complement neg?)))
  9.  
  10. (s/def ::summary-res
  11. (s/keys :req-un [::file-count
  12. ::operations
  13. ::time-total]))
  14.  
  15. (s/fdef combine-summaries
  16. :args (s/cat :xs (s/coll-of ::summary-res :min-count 1))
  17. :ret ::summary-res)
  18.  
  19. (defn combine-summaries
  20. [summaries]
  21. (letfn [(deep-merge [a b]
  22. (merge-with (fn [x y]
  23. (if (map? y)
  24. (deep-merge x y)
  25. (+ x y)))
  26. a b))]
  27. (reduce deep-merge summaries)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement