Re: clojure.spec and generic map with couple of special keys
That’s what I needed! Thanks On Tue, Jul 5, 2016 at 8:15 PM gsnewmark wrote: > If I'm not mistaken, similar issue was recently discussed on the > Clojurians Slack (direct link - > https://clojurians.slack.com/archives/clojure-spec/p146738221722 , > archive link - > https://clojurians-log.clojureverse.org/clojure-spec/2016-07-01.html - > discussion starts from @ghadi's post at 17:10:00). > > The basic idea is to validate namespaced keywords first, remove them using > the conformer, and then validate rest of the keys. > > > On вт, лип 5, 2016 at 4:32 , Sam Estep wrote: > > I ran into this same issue while trying to spec Clojure's destructuring > language. I asked a question about this on Stack Overflow: > http://stackoverflow.com/q/38151446/5044950 > > On Tuesday, July 5, 2016 at 9:16:40 AM UTC-4, Nikita Prokopov wrote: >> >> Imagine I have a generic keyword => string map with a special key that >> stores a number: >> >> { ::count 7 >> :x "x" >> :y "y" >> :z "z" >> ... } >> >> Both cases are easy to validate on their own: >> >> (s/def ::count number?) >> (s/conform (s/keys ::count) { ::count 7 }) >> >> (s/conform (s/map-of keyword? string?) { :x "x", :y "y", :z "z" }) >> >> But how do I write a spec to validate them when they are in a single map? >> >> I tried to use s/every but then another problem popped up: how do I >> reference or check another spec from inside s/every predicate? In my case, >> values are more complex than string? and have their own spec. >> >> Please help >> >> Nikita >> > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to clojure@googlegroups.com > Note that posts from new members are moderated - please be patient with > your first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en > --- > > You received this message because you are subscribed to the Google Groups > "Clojure" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to clojure+unsubscr...@googlegroups.com. > > > For more options, visit https://groups.google.com/d/optout. > > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to clojure@googlegroups.com > Note that posts from new members are moderated - please be patient with > your first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en > --- > You received this message because you are subscribed to a topic in the > Google Groups "Clojure" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/clojure/WiMV5EEAVhM/unsubscribe. > To unsubscribe from this group and all its topics, send an email to > clojure+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: clojure.spec and generic map with couple of special keys
If I'm not mistaken, similar issue was recently discussed on the Clojurians Slack (direct link - https://clojurians.slack.com/archives/clojure-spec/p146738221722 , archive link - https://clojurians-log.clojureverse.org/clojure-spec/2016-07-01.html - discussion starts from @ghadi's post at 17:10:00). The basic idea is to validate namespaced keywords first, remove them using the conformer, and then validate rest of the keys. On вт, лип 5, 2016 at 4:32 , Sam Estep wrote: I ran into this same issue while trying to spec Clojure's destructuring language. I asked a question about this on Stack Overflow: http://stackoverflow.com/q/38151446/5044950 On Tuesday, July 5, 2016 at 9:16:40 AM UTC-4, Nikita Prokopov wrote: Imagine I have a generic keyword => string map with a special key that stores a number: { ::count 7 :x "x" :y "y" :z "z" ... } Both cases are easy to validate on their own: (s/def ::count number?) (s/conform (s/keys ::count) { ::count 7 }) (s/conform (s/map-of keyword? string?) { :x "x", :y "y", :z "z" }) But how do I write a spec to validate them when they are in a single map? I tried to use s/every but then another problem popped up: how do I reference or check another spec from inside s/every predicate? In my case, values are more complex than string? and have their own spec. Please help Nikita -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: clojure.spec and generic map with couple of special keys
I ran into this same issue while trying to spec Clojure's destructuring language. I asked a question about this on Stack Overflow: http://stackoverflow.com/q/38151446/5044950 On Tuesday, July 5, 2016 at 9:16:40 AM UTC-4, Nikita Prokopov wrote: > > Imagine I have a generic keyword => string map with a special key that > stores a number: > > { ::count 7 > :x "x" > :y "y" > :z "z" > ... } > > Both cases are easy to validate on their own: > > (s/def ::count number?) > (s/conform (s/keys ::count) { ::count 7 }) > > (s/conform (s/map-of keyword? string?) { :x "x", :y "y", :z "z" }) > > But how do I write a spec to validate them when they are in a single map? > > I tried to use s/every but then another problem popped up: how do I > reference or check another spec from inside s/every predicate? In my case, > values are more complex than string? and have their own spec. > > Please help > > Nikita > -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
clojure.spec and generic map with couple of special keys
Imagine I have a generic keyword => string map with a special key that stores a number: { ::count 7 :x "x" :y "y" :z "z" ... } Both cases are easy to validate on their own: (s/def ::count number?) (s/conform (s/keys ::count) { ::count 7 }) (s/conform (s/map-of keyword? string?) { :x "x", :y "y", :z "z" }) But how do I write a spec to validate them when they are in a single map? I tried to use s/every but then another problem popped up: how do I reference or check another spec from inside s/every predicate? In my case, values are more complex than string? and have their own spec. Please help Nikita -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.