This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-12-11
Channels
- # adventofcode (42)
- # asami (13)
- # babashka (40)
- # beginners (25)
- # calva (39)
- # cider (18)
- # circleci (6)
- # cljs-dev (3)
- # clojure (39)
- # clojure-europe (16)
- # clojure-norway (9)
- # clojure-uk (2)
- # clojurescript (42)
- # datalevin (4)
- # datomic (23)
- # fulcro (33)
- # jobs (1)
- # malli (26)
- # minecraft (1)
- # off-topic (88)
- # pedestal (3)
- # polylith (8)
- # re-frame (6)
- # remote-jobs (2)
- # shadow-cljs (20)
- # tools-deps (12)
- # xtdb (5)
Q: I have a single arg fn that I am trying to generatively test. The single arg is vector that is checked using a :catn schema. when I use the => syntax, it interprets the nested :catn schema for the fn arity instead of treating it as a single arg. has anyone figured out how to do this?
Yeah. Simple but not easy. I can work around it by wrapping with another fn with a map arg.
thx @U055NJ5CC I’ll give that a try
Reading @afoltzm FSM post again, I returned to the idea of some sort of schema router / compiler, where an or
of schemas will pull out the common denominator then dispatch to the difference
Thoughts?
Imagine [:or [:map [:a any?] [:b any?]] [:map [:a any?] [:c any?]]]
=> [:and [:map [:a any?]] [:or [:map [:b any?]] [:map [:c any?]]]]
to start with, even smarter to have a dispatch to the correct schema instead of or
Sounds like a malli.diff
namespace might be an interesting idea, because this concept may be applicable beyond just :or
schemas – for example, you'd be able to compare two seqex schemas and say things like "sequence B can contain all the same elements as sequence A except for elements X and Y"
Sure, https://fabricate-site.github.io/fabricate/finite-schema-machines.htmlhtml @mynomoto
pluggable optimizer is a great idea, here's one stab at it: https://github.com/miikka/boolean-simplifier
@U7XR2PZFW's work on inference could intersect with this as well. Every type of/or schema can represent a set of predicates. A predicate can be a singular predicate, a segment (upper and lower bounds) or finite domain (min max)
Sounds like roughly equivalent to sub-typing for structural types. If we assume collections are covariant with respect to elements, functions are contravariant with respect to arguments, and a few other assumptions, I suspect small-ish rule system could be used to implement a sub-type predicate.
We can even unpack map schemas to a closed set of predicates, being map? and a set of all the entry predicates. Same for tuples. Then conjunction and disjunction are pretty well defined and we remain in predicate land and not structure. Not sure if it's good
Roughly:
(defprotocol SchemaDomain
(-conj [this that]) ;; and
(-disj [this that]) ;; or
(-isa? [this that])
(-walk [this]))
(defrecord EntrySchema [k v]
(-conj [this that]
(EntrySchema. k (-conj v (:v that))))
(-disj [this that]
(EntrySchema. k (-disj v (:v that)))))
(defrecord PredicateSchema [p]
(-conj [this that]
(cond
(-isa? this that) this
(-isa? that this) that
:else (-and this that)))
(-disj [this that]
(cond
(-isa? this that) that
(-isa? that this) this
:else (-or this that))))
I've encountered an issue where sequence schemas appear not to preserve metadata of input collections:
(meta (m/decode
[:schema {:decode/get {:enter identity}} [:cat [:= :start] :map]]
(with-meta [:start {:a 2}] {:meta true})
(mt/transformer {:name :get})))
;; => nil
(meta (m/encode
[:schema {:encode/get {:enter identity}} [:cat [:= :start] :map]]
(with-meta [:start {:a 2}] {:meta true})
(mt/transformer {:name :get})))
;; => nil
is this expected behavior, or should malli
preserve this information?(happy to file an issue on GitHub if it would be helpful)