This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-12-12
Channels
- # adventofcode (67)
- # announcements (8)
- # babashka (46)
- # beginners (154)
- # calva (5)
- # cider (9)
- # clara (5)
- # clj-kondo (34)
- # cljdoc (31)
- # cljsrn (4)
- # clojure (146)
- # clojure-europe (5)
- # clojure-italy (3)
- # clojure-losangeles (2)
- # clojure-nl (149)
- # clojure-spec (22)
- # clojure-uk (73)
- # clojured (6)
- # clojurescript (95)
- # clojureverse-ops (3)
- # cryogen (7)
- # cursive (12)
- # data-science (1)
- # datomic (9)
- # docker (1)
- # emacs (1)
- # figwheel-main (1)
- # hyperfiddle (1)
- # jobs (3)
- # malli (29)
- # nrepl (2)
- # off-topic (61)
- # pathom (6)
- # pedestal (1)
- # planck (1)
- # reitit (19)
- # shadow-cljs (52)
- # spacemacs (5)
- # tools-deps (24)
- # vim (30)
- # yada (6)
here's what I tried:
(defn max-length?
([n s]
(and (string? s) (< (count s) n)))
)
(def default-registry (merge m/default-registry {:max-length (m/fn-schema :max-length preds/max-length?)}))
I then should be able to say this, right?
(m/validate [:max-length 4] "bubu" {:registry default-registry})
but alas
#error{:cause ":malli.core/child-error",
:data {:type :malli.core/child-error, :data {:name :max-length, :properties nil, :children (4), :min 0, :max 0}},
@johan178 sure. could be just :default
property and a pre-defined transformer to use that for missing values. metosin/schema-tools
has just about that.
need to add capability to transform all schemas, so need a small development before it can work. Please raise an issue.
Hey @ikitommi I'm in the process of fixing up transforms for independent leaves and enters (and reverse order). I have a few questions for you while I'm in here...
1. For the collection transformer, right now fwrap
auto-coerces things into the appropriate type. This happens after the value-transformer
is called currently - meaning that I don't think it's possible for the value-transformer
to change it's collection type on encode
because it'll always be coerced back. Should we keep this behavior?
2. the map-of
transformer currently calls transform keys and transform values at the same time as it iterates through the map. I think it's fine to keep this for enter and leave? ie. it'll basically be enter: transform-map -> transform k 1 -> transform v 1 -> transform k 2 -> transform v 2
and leave: transform k 1 -> transform v 1 -> transform k 2 -> transform v 2 -> transform map
3. The collection transformer currently does a single step of building the collection and mapping the values. We probably want to do enter: coll-transform -> transform children
and leave: transform-children -> transform
1) I think the fwrap
should be removed and moved under Transformer decoders. e.g. as the arrays are always mapped to Clojure vectors in JSON decoding (by json parsers in both clj & cljs), with mt/json-transformer
there should be no transformation needed for :vector
, only for other sequence types. The currently silly mt/collection-transformer
could have decoders for all collection types.
Re. 1 I want to land this PR w/o that then if you don't mind. It's already huge
The other thing that we don't do much, that I'm going to add, if you think it's a good idea, is ensuring that the type doesn't change between transforms
ie. if a map encodes itself to an integer, we still try and call reduce-kv
on it for the key and value transformers
We likely shouldn't do that
Actually - I'm going to keep this focused at just the changes to fix #140 and the encode decode order - we can add more later
I'm still using transducers where possible
depending on how the collection is transformed, retaining the type automatically or not
and using fempty etc
I tried to be mindful of the performance implications - but a close look is definitely a good idea!
Cool, PR incoming
Catch you later!