This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-02-06
Channels
- # beginners (49)
- # calva (12)
- # cider (5)
- # cljdoc (4)
- # clojure (51)
- # clojure-dev (1)
- # clojure-europe (16)
- # clojurescript (56)
- # conjure (2)
- # copenhagen-clojurians (1)
- # core-async (4)
- # data-science (4)
- # docker (1)
- # emacs (4)
- # gratitude (1)
- # malli (2)
- # meander (2)
- # missionary (7)
- # off-topic (23)
- # pedestal (3)
- # polylith (6)
- # shadow-cljs (28)
- # spacemacs (1)
- # sql (9)
- # transit (8)
I've got something else that I want to improve as well. I'm not blocked on this since I've got a workaround but I don't like the workaround.
(defn my-fun
[x]
(apply merge
(m/rewrites x
{:thing {:map ?stuff}
:min ?length
:max ?length
:map-entries (m/some ?entries)}
{:entity {:stuff ?stuff
:entries ?entries}}
{:thing {:map ?stuff}
:map-entries (m/some ?entries)}
{:map {:stuff ?stuff
:entries ?entries}}
{:thing {:list ?stuff}
:list-entries (m/some ?entries)}
{:list {:stuff ?stuff
:entries ?entries}})))
(my-fun {:thing {:map 'stuff}
:min 1
:max 3
:map-entries [1 2 3]})
;; {:map {:entries [1 2 3]}}
(my-fun {:thing {:map 'stuff}
:min 1
:max 1
:map-entries [1 2 3]})
;; produces
;; {:entity {:entries [1 2 3]}, :map {:entries [1 2 3]}}
;; but i only want
;; {:map {:entries [1 2 3]}}
(my-fun {:thing {:map 'stuff
:list 'other-stuff}
:min 1
:max 3
:map-entries [1 2 3]
:list-entries 't})
;; {:map {:stuff stuff, :entries [1 2 3]}, :list {:stuff other-stuff, :entries t}}
(my-fun {:thing {:map 'stuff
:list 'other-stuff}
:min 1
:max 1
:map-entries [1 2 3]
:list-entries 't})
;; produces
;; {:entity {:stuff stuff, :entries [1 2 3]}, :map {:stuff stuff, :entries [1 2 3]}, :list {:stuff other-stuff, :entries t}}
;; but I only want
;; {:entity {:stuff stuff, :entries [1 2 3]}, :list {:stuff other-stuff, :entries t}}
;; should only return either :map or :entity, not both
I was trying to generate a schema from spec-provider stats output. I want rewrites to return multiple matches in case it's a map and a list but I don't want it to return "entity" and "map" together since "entity" trumps" map. I'm guessing it's an entity if the data is uniform and falling back to a map collection if it's not. I still want to know if it's a map and a list so that I can wrap them both in an "or". Another example: "map" and "nil" makes a nilable map.