This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-06-30
Channels
- # beginners (23)
- # boot (3)
- # cider (5)
- # clara (12)
- # cljs-dev (15)
- # clojure (18)
- # clojure-spec (24)
- # clojure-uk (23)
- # clojurescript (24)
- # data-science (2)
- # datascript (1)
- # datomic (12)
- # fulcro (51)
- # jobs (1)
- # jobs-discuss (1)
- # leiningen (1)
- # nrepl (1)
- # off-topic (1)
- # onyx (2)
- # re-frame (6)
- # reagent (14)
- # rum (1)
- # shadow-cljs (12)
- # spacemacs (3)
- # specter (1)
- # tools-deps (37)
- # vim (2)
if I have a map:
(def m #::{:item1 #::{:name "whatever"
:description "..."
:ref []}
:item2 #::{:name "another one"
:description "...?"
:ref [:item1]})
can I write a spec so that all items in ::ref
are keys of the containing map?
(s/def ::ref (coll-of ...??...))
or
(s/def ::ref (key-set ...??...))
hmm yes
i think you can spec it as a predicate
let me try it out on my side first
something like that
(def m1 {:a {:b 1
:ref [:a]}})
(def m2 {:a {:b 1
:ref [:c]}})
(defn ref-contains-keys-of-containing-map [m]
(let [ks (keys m)]
(= (:ref (first (vals m))) ks)))
(s/def ::m (s/and map?
ref-contains-keys-of-containing-map))
(s/conform ::m m1)
(s/conform ::m m2)
m1
conforms, m2
doesn't
right, thx... will try.
oh right, but will see if I can make that more dynamic in some way... I'm fetching the map from outside. well... will see 😛
@clojurians.net I like ghostweel - just trying it now - but it doesn't validate the return value of >defn
. I seem to remember clojure.spec
itself doesn't either, but orchestra does so... Any plans to add this to ghostweel as well (validation of return values of functions)?
@kurt-o-sys have you configured to do so? there’s a separate config option to turn that on
;; Spec-instrument functions on namespace reload.
::instrument false
;; Spec-instrument functions on namespace reload using orchestra,
;; which spec-checks the output in addition to the input.
::outstrument false
I didn't... - I didn't know it was an option, but I do now 🙂.
😜 Glad to help!
from the README
@kurt-o-sys It's already in there! The option is ::g/outstrument
.
Didn't read the other replies before I answered. By the way there's a bug in the current stable version, where ::g/instrument
and ::g/outstrument
require ::g/check
to be enabled to have any effect. This doesn't really make any sense and is fixed in 0.2.2-SNAPSHOT, soon to be released as a stable 0.2.2 once some Figwheel issues have been cleared up.
nice, thx! I did figure it out concerning that ::g/check
issue, not about the ::g/oustrument
😛. Thanks a lot. Just one more question: how would you recommend instrumenting only during dev, but not for a prod build? (Just wondering what you consider as best practice)
also, I must be doing something wrong:
(>defn target
"target function to be minified"
{::g/instrument true
::g/outstrument true}
[in]
[any? => double?]
"wrong")
This should fail, right? (return value should be of type double
, but it's a string). However, it doesn't fail at all.
Adding the config to the ns
doesn't help either:
(ns test-gw.core
#:ghostwheel.core{:instrument true
:outstrument true}
(:require [clojure.spec.alpha :as s]
[ghostwheel.core :as g
:refer [>defn >defn- >fdef ? => | <-]])
...)
Don't use ::g/instrument
and ::g/outstrument
together, only one will be used, in this case ::g/instrument
. What you want here is only ::g/outstrument
.
And regarding not instrumenting in production – just make sure that ghostwheel isn't enabled in your prod build config
No way to do that in Clojure at the moment, so just don't do instrumentation there in production. 🙂
right, perfect 👍 👍
Speaking of which – 0.2.2 is out: https://github.com/gnl/ghostwheel/blob/master/CHANGELOG.md
