This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-06-22
Channels
- # beginners (8)
- # boot (41)
- # cider (1)
- # cljsrn (2)
- # clojure (91)
- # clojure-dev (34)
- # clojure-gamedev (3)
- # clojure-germany (6)
- # clojure-greece (324)
- # clojure-japan (2)
- # clojure-miami (4)
- # clojure-nl (6)
- # clojure-quebec (3)
- # clojure-russia (26)
- # clojure-spec (50)
- # clojure-uk (19)
- # clojurescript (147)
- # core-async (5)
- # css (2)
- # cursive (15)
- # datascript (7)
- # datomic (6)
- # hoplon (1)
- # jobs (4)
- # lein-figwheel (17)
- # off-topic (4)
- # om (52)
- # om-next (10)
- # onyx (1)
- # planck (19)
- # proton (1)
- # re-frame (81)
- # reagent (61)
- # spacemacs (1)
- # specter (46)
- # spirituality-ethics (7)
- # untangled (7)
- # yada (17)
I was expecting s/conform to return fully "conformed" data but it doesn't seem to work like that.
=> (s/conform (s/coll-of (s/conformer (fn [x] (println "I am conforming" x) (str x))) []) ["1" 2 :3])
I am conforming 1
I am conforming 2
I am conforming :3
["1" 2 :3]
it uses the conformer in order to check the data but returns the un-conformed data. Seems to be "non-recursive"
Is that intended behaviour? Perhaps I'm attempting to use it incorrectly - as a data verification & transformation tool.
The problem here is that coll-of samples its contents and doesn't flow the entire contents
There are some things in this area changing in next alpha
Thanks Alex, I think I see similar behaviour with map-of.
every and every-kv are new things already in master but not yet released
One of those sets will conform all args, although I'm not sure which
Perfect. Thanks.
Is there a way to spec values which will be conveyed over a channel or returned by a promise?
nothing built in yet
ultimately I expect there will be some things provided for core.async
you could supply a map transducer to an async channel that called s/conform or something like that though
some kind of spec wrapper which takes a spec and validates channel values on the go would be nice
I only like to be sure that nothing speaks at this conceptionally before spec gets final
test.check has a fn (`fmap`) that lets you call an arbitrary fn on the results of a generator. But is there any way to create a generator that just calls an arbitrary fn? I haven't found one.
The only solution I've found so far is to do (fmap (fn [_] do-what-I-want) some-arbitrary-gen)
, but it's pretty ugly to put in a generator and then ignore what it generates.
(I understand that shouldn't be a typical use, but it'd be good to have an escape hatch for cases where you have an existing source of randomness that you don't want to have to duplicate)
@eggsyntax: As you said already, it’s not the typical use to implement the root generator yourself. You have to understand that test.check needs to control the generated values in a way to get shrinking work. So I have no answer to your question only the suggestion: Don’t do this! 🙂
Although in this case I'm still gonna do it...again, existing (complex) source of domain-specific randomness.
@eggsyntax: have you looked at return
?
@alexmiller: I have, but it looks like that'll only generate a constant value, right? I need something that'll call a fn every time it needs a new one.
test.check does have a no-shrink qualifier too I believe.
If the value doesn't benefit from shrinking (like uuids for ex)
has anyone come up with a reasonable clojure.spec/def
for a database argument?
all I’m using at the moment is ::s/any
(defn get-user [db id] ...)
(s/def ::database ::s/any)
(s/def ::user (s/keys :req [::id ::email]))
(s/fdef get-user
:args (s/cat :db ::database :id ::id)
:ret ::user)
but obviously that won’t work with generators
I’m not sure there’s much value here, but interested in hearing what a possible solution might be
@bostonaholic: what should the DB argument look like?
well, it’s a datomic db
yeah, sorry
that’s why I’m thinking this isn’t a good idea
@alexmiller picking up on my question about fully conforming yesterday. I tried every-kv this morning (cljs release) and I see the same behaviour:
=> (do
(s/def ::tree (s/or
:branch (s/every-kv keyword? ::tree)
:value ::s/any))
(s/conform ::tree {:A {:B 2}}))
[:branch {:A {:B 2}}]
Was hoping for [:branch {:A [:branch {:B [:value 2]}]}]
or similar.yeah, that’s the only other thing I could think of
That's enough to show it's a legit database...you could also do something like
(s/and #(instance? datomic.db.Db %)
(s/keys :req-un [::key1 ::key2]))
with further specs for those keys.
(don't have a datomic-using project right in front of me, I'm improvising on the type, and assuming that it's a record
)you’re right
@olivergeorge its not done yet
@bostonaholic: ooh, quite a few keys there, huh? (:id :memidx :indexing :mid-index :index :history :memlog :basisT :nextT :indexBasisT :elements :keys :ids :index-root-id :index-rev :asOfT :sinceT :raw :filt)
heh, yeaahhhhhhhhh
@olivergeorge: I believe when it is done map-of will be what you want