This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-04-15
Channels
- # asami (6)
- # babashka (74)
- # babashka-sci-dev (164)
- # beginners (50)
- # biff (3)
- # calva (71)
- # clj-kondo (4)
- # cljdoc (39)
- # cljsrn (4)
- # clojars (8)
- # clojure (70)
- # clojure-austin (7)
- # clojure-czech (5)
- # clojure-europe (4)
- # clojure-losangeles (1)
- # clojure-nl (10)
- # clojure-norway (1)
- # clojure-uk (3)
- # clojurescript (38)
- # community-development (18)
- # cursive (129)
- # datomic (9)
- # fulcro (7)
- # graalvm (4)
- # improve-getting-started (1)
- # jobs (1)
- # kaocha (2)
- # liberator (9)
- # lsp (22)
- # malli (3)
- # membrane (95)
- # off-topic (86)
- # releases (2)
- # sci (5)
- # specter (2)
Hi. Say I want to validate a sequence of maps and make sure there's at least one of them with a specific entry. Is this in scope for Malli? How would I go about it? Example:
;; my schema is something that somehow looks for [:b 2] in a map sequence
(m/validate my-schema [{:a 1} {:b 2} {:c 3}])
=> true
(m/validate my-schema [{:a 1} {:b 2} {:b 2 :c 4} {:c 3}])
=> true
(m/validate my-schema [{:a 1} {:c 3}])
=> false
🙌 1
you can use https://cljdoc.org/d/metosin/malli/0.8.4/doc/readme#fn-schemas to validate "anything":
(def my-schema
[:and
[:sequence map?]
[:fn (fn [s] (some #(= 2 (:b %)) s))]])
i haven't tried that but it should workI’m sure this has been asked before, but is there a way to generate a value compared to the generated value of a key in the same map schema?
{:min-value 250 ;; generated
:max-value 350} ;; always exactly 100 more than min
Looking through the documentation, I can’t find anything specific. https://github.com/metosin/malli/blob/master/docs/tips.md#dependent-string-schemas looks promising or maybe using :gen/fmap
but I could really use some guidance.