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@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"]}
@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?
@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]]]
by default it conforms to coll of the same type as input coll. :into
overrides this
@vlaaad thanks! don't know there's a into
option.
this is what I'm looking for
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 😉
"soon" is still many months :)
what are the most difficult parts? design or implementation?
I didn't say which Conj
lol 🙂
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!"