Fork me on GitHub
#clojure-spec
<
2020-06-17
>
tianshu07:06:12

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

vlaaad07:06:28

@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"]}

tianshu08:06:32

@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?

vlaaad08:06:13

@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]]]

vlaaad08:06:25

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

tianshu08:06:40

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

tianshu08:06:48

this is what I'm looking for

borkdude12:06:35

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 😉

Alex Miller (Clojure team)12:06:59

"soon" is still many months :)

Vincent Cantin08:06:02

what are the most difficult parts? design or implementation?

Alex Miller (Clojure team)13:06:12

I didn't say which Conj

🎉 3
6
🙏 3
Aron13:06:17

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!"