This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-11-19
Channels
- # adventofcode (5)
- # announcements (1)
- # babashka (44)
- # beginners (83)
- # biff (10)
- # calva (1)
- # cherry (3)
- # cider (10)
- # clojure (78)
- # clojure-europe (12)
- # clojure-norway (1)
- # conjure (1)
- # cryogen (1)
- # datascript (4)
- # dev-tooling (2)
- # gratitude (2)
- # lsp (4)
- # malli (6)
- # off-topic (15)
- # polylith (9)
- # quil (19)
- # releases (1)
- # sci (6)
- # scittle (64)
- # sql (10)
- # squint (35)
Hello, I would like to define a schema with namespaced keywords and then coerce a map that does not have namespaced keywords into a valid map with the appropriate namespaced keywords. Something like 👇 Can anyone help me come up with a good way to do this?
(ns super.cool.namespace
(:require
[malli.core :as mc]
[malli.error :as me]))
(def Schema
[:map
[::foo :string]
[::bar :into]])
(def data {:foo "clojure"
:bar 2})
(mc/coerce Schma data ?)
=> {:super.cool.namespace/foo "clojure"
super.cool.namespace/bar 2}
I think it would be simpler if it just would create a transforming map in :compile
{:foo ::foo, :bar ::bar}
… so, no :ns
declaration would be needed. 1
Thanks @U055NJ5CC that example worked for me.
I agreed that needing the :ns
key isn't ideal. I think that having a map could be helpful if you want to do something articulate. But wouldn't it be best to just be able to get the namespace from the namespace of the key?