Fork me on GitHub
#clojure-spec
<
2020-05-16
>
Kyle Brodie01:05:47

Whats the best way to spec numbers as strings so something like "12.53" will be generated?

seancorfield02:05:35

It has specs that accept strings or longs and generate as strings that are parseable as longs. Should give you something to work from.

Kyle Brodie02:05:00

@seancorfield Thank you! That library looks very helpful. I might have to write my own date though because mine are "YYYY-MM-DD". Unless "yyyy-M-d" is the right format for zero padded in java-time

seancorfield03:05:45

Yeah, it'll do zero-padded. And you want yyyy and d lowercase for dates.

Kira McLean11:05:09

Hi there.. I’m just getting started with spec, have a somewhat noob question that I’m having trouble finding an answer to: Is it possible to have two different specs for the value of a given un-qualified keyword? I.e. I have a map and I know that the values might have different requirements in different contexts, but I would like to keep re-using the same key. So I have specs like this (`fs` is [datoteka.core :as fs] ):

(s/def ::path fs/path?)
(s/def ::html-path (s/and ::path (partial matches-ext "html")))
(s/def ::content string?)

;; This one is great -- checks my maps like {:path ,,, :content ,,,}
(s/def ::page (s/keys :req-un [::path ::content]))

;; Here is the issue: I want to check a map that also has the keys [:path 
;; :content], not one with an html-path key
(s/def ::html-page (s/keys :req-un [:path ::html-path ::content])) 
In the ::html-page spec I want :path to match the html-path spec but for the key to still be called :path . Is this possible?

ghadi11:05:20

If you define two specs, :a.b.c/path and :x.y.z/path you can use them to spec unqualified keys in different maps

Kira McLean16:05:19

Makes perfect sense, thanks.

David Pham18:05:12

Are there good library to use with clojure.spec? 🙂

salam18:05:16

@neo2551 you can find spec libraries (along with other libraries) here: https://www.clojure-toolbox.com/

Kira McLean20:05:07

Can you write a function spec for a multi-method? If so, any chance anyone can share an example of this somewhere?

favila21:05:00

You can spec the method, but afaik not the implementations

favila21:05:08

Caveat with fspec on mm: instrumentation changes the type to a fn, so future defmethods will fail with a type error

favila21:05:00

You need to unstrument before evaluating more defmethods

Kira McLean23:05:48

Interesting.. good to know. Yeah I’m curious about whether it’s possible to spec the implementations of a multimethod. I couldn’t find any examples online, but so far I’ve found with clojure that doesn’t always mean it’s not possible.

Alex Miller (Clojure team)23:05:52

You can spec the dispatch method used in the mm if that’s useful

Kira McLean23:05:49

That’s something! But good to know, thanks!

telekid00:05:02

I’m not sure if this is useful or relevant to your goals, but: https://gist.github.com/telekid/f2e588718dbdfe48306d64e5388bdc15

Kira McLean21:05:18

Ah this is really cool! Never thought of separating out the args and mm to spec separately. Perhaps a little unorthodox or is this normal? But definitely interesting. Thanks!