clojure-spec

About: http://clojure.org/about/spec Guide: http://clojure.org/guides/spec API: https://clojure.github.io/spec.alpha/clojure.spec.alpha-api.html
tianshu 2020-06-17T07:08:12.364400Z

I'm trying to use s/coll-of ... :kind map? and s/or

(s/def ::k-str (s/tuple keyword? string?))
(s/def ::k-num (s/tuple keyword? number?))
(s/def ::kv (s/or
             :k-str ::k-str
             :k-num ::k-num))

(s/conform (s/coll-of ::kv :kind map?) {:a 1 :b "2"})
;; => {:a [:a 1], :b [:b "2"]}
I have no idea what the conform result should be, but this one looks not right

vlaaad 2020-06-17T07:28:28.364800Z

@doglooksgood what about map-of?

sandbox=> (s/conform (s/map-of keyword? (s/or ::string string? ::number number?)) {:a 1 :b "2"})
{:a [:sandbox/number 1], :b [:sandbox/string "2"]}

tianshu 2020-06-17T08:23:32.367100Z

@vlaaad Thanks for the advice! But I want care about both key and value. You remind me, since there's a map-of , so coll-of is only designed to work with sequences?

vlaaad 2020-06-17T08:29:13.367600Z

@doglooksgood figured it out after reading coll-of docstring:

(s/conform (s/coll-of (s/or
                        :kw->num (s/tuple keyword? number?)
                        :kw->str (s/tuple keyword? string?))
             :kind map?
             :into [])
  {:a 1 :b "2" :c 1})
=> [[:kw->num [:a 1]] [:kw->str [:b "2"]] [:kw->num [:c 1]]]

vlaaad 2020-06-17T08:30:25.368300Z

by default it conforms to coll of the same type as input coll. :into overrides this

tianshu 2020-06-17T08:41:40.368900Z

@vlaaad thanks! don't know there's a into option.

tianshu 2020-06-17T08:41:48.369100Z

this is what I'm looking for

borkdude 2020-06-17T12:14:35.370300Z

Re: god I hope it's not years 🙂 (https://clojurians.slack.com/archives/C1B1BB2Q3/p1591980460308000) Reminded me of: > We're hoping to have something releasable by Conj or the end of this year Source: https://youtu.be/KeZNRypKVa4?t=1201 Approaching one year away from that talk soon 😉

alexmiller 2020-06-17T12:59:59.371Z

"soon" is still many months :)

2020-06-20T08:16:02.397400Z

what are the most difficult parts? design or implementation?

alexmiller 2020-06-17T13:00:12.371300Z

I didn't say which Conj

🙏 1
2
🎉 1
borkdude 2020-06-17T13:08:39.371500Z

lol 🙂

Aron 2020-06-17T13:48:17.373400Z

A school administrator in a speech said once (and I heard it with my own ears), "in 2000, by 9 o'clock, we will finish the new school building!"