This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-11-18
Channels
- # beginners (84)
- # boot (21)
- # cider (12)
- # cljs-dev (13)
- # cljsrn (3)
- # clojure (169)
- # clojure-dusseldorf (2)
- # clojure-gamedev (6)
- # clojure-germany (1)
- # clojure-russia (15)
- # clojure-serbia (4)
- # clojure-spec (16)
- # clojure-uk (4)
- # clojurescript (51)
- # core-async (1)
- # datomic (23)
- # emacs (16)
- # figwheel (1)
- # fulcro (60)
- # hoplon (8)
- # lein-figwheel (3)
- # leiningen (1)
- # luminus (4)
- # lumo (43)
- # off-topic (4)
- # re-frame (17)
- # rum (37)
- # shadow-cljs (21)
- # test-check (13)
- # vim (14)
does spec have a way to capture: this object is an ATOM and when you deref the ATOM, it should satisfy this spec
I haven’t seen anything like that. I suppose you could wrap an atom and hook spec on derefs?
We can set a validator-function on the atom, so it'll auto reject on swap! / reset! if it fails the spec.
However, I now want a way to get the validator function of an atom, so we can say things like "assert that this atom has FOOBAR validator"
You also have the same problem for things like manifold deferreds
@danielcompton: this looks interesting ; does it also have cljs support ? [ I can't find mention of it anywhere on the page ]
@U0FT7SRLP: thanks for the manifold-cljs link; much appreciated
1. Please ignore the camelCase. 2
[(s/assert ::appState 23)
(s/valid? ::appState 23)]
(comment
[23 false])
3. How is this possible? if 23 is not a valid ::appState, shouldn't assert throw an exception ?There’s a CLJS port of it somewhere
I have a simple function that takes data, and creates test data from it. Currently, it uses (rand-int ..), what minimum changes do I need to do to this code, in order to use the same seed for random as the rest of the generators.
(defn create-update-operation
"Change or delete or add a new key to `m`.
In 30% of the operations, then value will be nil, i.e. delete."
;; Do not change or delete any of the pre-defined keys
([m] (let [res (create-update-operation (filter #(not (#{:id :tenant :entity :k :updated :version} (key %))) m) {})]
;; (println (count res))
res))
([m changes]
(if (<= (count m) 3) changes
;; find the next key to change (update or delete)
(let [nxt (rand-int (count m))
next (nth m nxt)
rest (nthrest m (min 1 nxt)) ;0 just mean that I am regenerating the first key.
k (key next)
_ (assert (some? k))
v (update-or-delete-value k)
changes2 (assoc changes k v)]
;; see if we should add a new key to the map
(if (< (rand-int 10) 2)
(recur rest (let [k2 (keyword (random-string))
v2 (update-or-delete-value k2)]
(assoc changes2 k2 v2)))
(recur rest changes2))))))
where update-or-delete-value
also uses rand-int