Fork me on GitHub
#announcements
<
2019-03-31
>
danielcompton07:03:11

Announcing the intial release of defn-spec, a library to create specs inline with your defn. It uses the same syntax as Schema, so you probably already know how to use it. https://danielcompton.net/2019/03/31/announcing-defn-spec https://github.com/danielcompton/defn-spec

👏 52
8
pez08:03:49

About attrs maps in functions. I use them pretty often. Mostly for pre and post predicates (which I guess is less important with this library), but also for inlining tests.

vemv08:03:15

@U0ETXRFEW interesting! How do you run those inline tests?

pez09:03:11

Same way as I run any tests. The Clojure test runner looks there for them. Unfortunately the ClojureScript test runner does not. I tried to fix that a while ago, but my macro fu was insufficient.

vemv09:03:55

Nice. How how do the defns themselves look like? Can't imagine ^^

pez09:03:53

Like so:

(defn absolute
  "The absolute value of a number."
   {:test (fn []
            (is= (abs 5) 5)
            (is= (abs -2) 2)
            (is= (abs 0) 0))}
  [x]
  {:pre [(number? x)]}
  (if (pos? x)
    x
    (- x)))

pez09:03:39

Which shows us that I lied. The pre-post-map is a separate one. 😄

pez09:03:45

Also in that example I am using some convenience macros from ysera.test.

vemv09:03:35

Really nice. Not sure if will immediately adopt, but happy to learn!

pez09:03:39

I can recommend giving inline tests a try. I sometimes fall into a very sweet flow of doing my REPL experiments inside that attrs-map, where some of the experiments will stay as tests.

danielcompton16:03:52

@U0ETXRFEW the attr maps that don't work are ones that you put at the end of your function definition after all of the arities

danielcompton16:03:08

Looking at the definition (defn name doc-string? attr-map? ([params*] prepost-map? body) + attr-map?) it's the last attr-map? which isn't supported

pez17:03:02

Got it. Amazing.

danielcompton17:03:05

Yeah, I didn't even know they were a thing

👍 4
jaide15:04:13

Wow! Here I was thinking Elixir’s doc-string tests were really clever, Clojure accomplished the same thing except even more simple — it’s just a map with regular Clojure instead of a specially formatted string.

carocad12:03:47

I just releases the v0.3.0 of https://github.com/hiposfer/rata. A library to help manage state on Clojurescript app with Datascript and Reagent 🙂. Your feeback is most welcome

🚀 4