This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-12-12
Channels
- # adventofcode (42)
- # aleph (10)
- # announcements (1)
- # asami (138)
- # babashka (7)
- # beginners (7)
- # biff (13)
- # cider (7)
- # clj-kondo (15)
- # clojure (53)
- # clojure-austin (11)
- # clojure-belgium (2)
- # clojure-europe (23)
- # clojure-nl (1)
- # clojure-norway (55)
- # clojure-sweden (5)
- # clojure-uk (4)
- # cryogen (7)
- # cursive (63)
- # datomic (5)
- # eastwood (6)
- # emacs (31)
- # fulcro (7)
- # hyperfiddle (9)
- # introduce-yourself (3)
- # java (11)
- # lsp (10)
- # malli (14)
- # membrane (35)
- # off-topic (13)
- # portal (12)
- # prelude (1)
- # releases (2)
- # ring-swagger (27)
- # shadow-cljs (8)
- # timbre (25)
Hello!
How correct is it that in regexp we cut off uuid with upper case? What do you think?
I used to be able to pass such uuid in old versions for example 0525AEAC-310A-4B2F-91EA-DD940AA1C30D
(def ^:private uuid-re
#"(?i)^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$")
(defn -string->uuid [x]
(if (string? x)
(if-let [x (re-matches uuid-re x)]
#?(:clj (UUID/fromString x)
:cljs (uuid x))
x)
x))
Standards such as https://www.itu.int/en/ITU-T/asn1/Pages/UUID/uuids.aspx and https://www.rfc-editor.org/rfc/rfc4122 require them to be formatted using lower-case letters, but also require parsers to accept upper-case letters.
this regex is case insensitive. at least in clojure. but I'm not sure about cljs
if regex begins with (?i) it should be case insensitive
you're right. Hmm, that's freakin' weird. I'll keep looking into why it's not working for me.
I have a version 0.10.4 where
(def ^:private uuid-re
#"^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$")
:melting_face:that's definitely a bug)
Is it possible to schema def a :namespace
"value" itself?
> (type *ns*)
clojure.lang.Namespace
Trying to write a recursive schema for a nested string map representing all loaded namespaces with this shape:
{"aleph" {"flow" {:ns aleph.flow}
"http" {:ns aleph.http}
"netty" {:ns aleph.netty}}
...}
This schema works using a more generic match with :some
(def =>ns-tree
[:schema {:registry
{::ns-tree
[:map-of :string
[:or
[:ref ::ns-tree]
[:map [:ns :some]]]]}}
::ns-tree])
Assuming the value associated to :ns
is always a symbol, using :fn
with a predicate like (comp some? (partial find-ns))
Thanks, this worked with a tweak. My value in :ns
is an actual namespace "object" & find-ns can't take it
A quick call to str
stops the exception -- [:fn (comp find-ns symbol str)]
I assume this was too niche or that there's pragmatic reasons that :namespace
isn't a Malli builtin -- but I'm willing to PR it if anyone sees this thread in the future & wants it.
If you have an actual namespace object, then you can use a predicate like (partial instance? clojure.lang.Namespace)
e.g.
user=> (instance? clojure.lang.Namespace (find-ns 'user))
true
Minor caveat: this only tests if an object is a Namespace, it does not tell you whether the corresponding namespace has been loaded or notI like that as a more performant and generic solution, not often I've needed instance?
Having a pred for a loaded namespace is useful but heavier & arguably dirty to include in an otherwise "pure" validation
(Sidenote: for writing a performant "is namespace loaded check", the-ns
is an interesting option that takes either a ns object or a symbol naming a namespace object. I've never seen this FN in a decade of Clojure so making a note here.
https://clojuredocs.org/clojure.core/the-ns )