This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-06-16
Channels
- # admin-announcements (1)
- # announcements (1)
- # babashka (130)
- # beginners (120)
- # calva (11)
- # cider (5)
- # clj-kondo (9)
- # cljsrn (17)
- # clojure (63)
- # clojure-australia (1)
- # clojure-canada (21)
- # clojure-europe (37)
- # clojure-israel (4)
- # clojure-uk (6)
- # clojurescript (170)
- # conjure (5)
- # core-async (23)
- # cursive (16)
- # datomic (4)
- # defnpodcast (1)
- # emacs (5)
- # fulcro (1)
- # gis (2)
- # graalvm (31)
- # graphql (4)
- # helix (6)
- # honeysql (16)
- # jobs-discuss (3)
- # juxt (1)
- # lsp (7)
- # malli (20)
- # meander (12)
- # missionary (6)
- # off-topic (50)
- # pathom (4)
- # re-frame (4)
- # react (1)
- # ring (2)
- # shadow-cljs (63)
- # spacemacs (2)
- # sql (15)
- # testing (6)
- # vim (8)
- # xtdb (7)
What's the rationale behind the fact that a set is considered as :sequential
?
For instance
(validate [:sequential string?] #{"aa"}) ;; false
it’s following the clojure way:
{:sequential (m/-collection-schema {:type :sequential, :pred sequential?})}
(sequential? #{}) ; => false
you should be able create custom collections types easily that access both sequentials and sets.
@ikitommi Could you share a pointer to the documentation about custom collection types?
sure: https://github.com/metosin/malli/blob/master/src/malli/core.cljc#L813. Documentation PRs most welcome 🙂
in use: https://github.com/metosin/malli/blob/master/src/malli/core.cljc#L1925-L1927
How it would look like to create a custom :sequential-or-set
predicate?
And where would i put its definition?
1. def a Var and use it instead of the type (keword), like with Reagent 2. add it to a registry, see README for alternatives
Ok. Thanls
@viebel sequential means: it has a defined order. sets are not ordered, similar to maps, although you can create sequences out of them
Yeah. It makes sense. But still surprising.
I think we need a name and a predicate for a bunch of things that could be either in a set or in a sequence
My use case is a function that receives a bunch of ids and return the entities whose id is contained in the bunch
coercion is always an option:
(m/decode
[:set :int]
[1 2 3]
(mt/collection-transformer))
; => #{1 2 3}
Any recommendations on how to approach extracting out a registry from a schema? For example:
[:map
[::id int]
[:name string?]
[::country {:optional true} string?]]
to
{::id int?
::country string?}
and as a nice to have, the schema simplified to use the new registry:
[:map
::id
[:name string?]
[::country {:optional true}]]
Use cases:
• Simplify large schemas
• Finding differences in semantics
• Refactoring multiple schemas to use a shared registry