View FizzBuzz.clj
;; try this form-by-form at a REPL
(require '[clojure.spec.alpha :as s])
;; create an inline DSL to describe the FizzBuzz world
(defmacro divides-by
[nm n]
`(s/def ~nm (s/and pos-int? #(zero? (mod % ~n)))))
;; specify FizzBuzz
(divides-by ::fizz 3)
View FizzBuzzTestSuite.edn
(1 2 "Fizz" 4 "Buzz" "Fizz" 7 8 "Fizz" "Buzz" 11 "Fizz" 13 14 "FizzBuzz" 16 17 "Fizz" 19 "Buzz" "Fizz" 22 23 "Fizz" "Buzz" 26 "Fizz" 28 29 "FizzBuzz" 31 32 "Fizz" 34 "Buzz" "Fizz" 37 38 "Fizz" "Buzz" 41 "Fizz" 43 44 "FizzBuzz" 46 47 "Fizz" 49 "Buzz" "Fizz" 52 53 "Fizz" "Buzz" 56 "Fizz" 58 59 "FizzBuzz" 61 62 "Fizz" 64 "Buzz" "Fizz" 67 68 "Fizz" "Buzz" 71 "Fizz" 73 74 "FizzBuzz" 76 77 "Fizz" 79 "Buzz" "Fizz" 82 83 "Fizz" "Buzz" 86 "Fizz" 88 89 "FizzBuzz" 91 92 "Fizz" 94 "Buzz" "Fizz" 97 98 "Fizz" "Buzz")
View specing_oddly_shaped_data.clj
(require '[clojure.spec.alpha :as s])
(s/def ::coord nat-int?)
(s/def ::x ::coord)
(s/def ::y ::coord)
(s/def ::xy (s/keys :req-un [::x ::y]))
(s/def ::point (s/map-of #{:point} ::xy))
(s/def ::username (s/and string? seq))
(s/def ::user (s/map-of #{:user} ::username))
View java_tx_fn_in_clojure.clj
(require '[datomic.api :as d])
(def uri "datomic:mem://foo")
(d/create-database uri)
(def conn (d/connect uri))
(def schema [{:db/ident :foo
:db/fn #db/fn
{:lang "java"
:params [db a b c]
:code "return a;"}}])
View clj-xchart-examples.clj
(def argses (->> (s/exercise ::cs/xy-chart-args 10 ex/generators)
(mapv first)))
View transcriptor-example.clj
(require '[cognitect.transcriptor :refer (check!)])
(+ 1 2)
(check! pos-int?)
View clojure_spec_missing_piece.clj
;; clojure.spec's missing piece, work in progress
;; this is only halfway done, somebody else will need to do the other 95%
(require
'[clojure.spec :as s]
'[clojure.spec.test :as test])
(defn naive-english-explain
"Copy and paste this into your app. Figure out what it does by
trying it in production."
View errors_as_data.clj
;; spec errors are data, and as such are composable with all the rest
;; of Clojure. The forms below show getting to an interesting part
;; of an error in a larger data structure, taking advantage of
;; edn-reading, pretty-printing, *print-length* and threading macro.
;; It is difficult to maintain the compositionality shown here
;; once you convert error data into e.g. ASCII art.
(require
'[clojure.edn :as edn]
View client_transduce_skeleton.clj
(a/transduce
(comp
(halt-when error?)
(map ...)
(filter ...))
(completing ...)
accumulator
query)
View add_at.clj
;; non-working add-at
(require '[boot.core :as core]
'[boot.tmpdir :as tmpd]
'[clojure.java.io :as io])
(deftask add-at
"Like sift :add-*, but lets you make a dest path in fileset"
[r rolekey ROLEKEY kw "rolekey"
s source SOURCE file "source path in project"
d dest DEST file "dest path in fileset"]