This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-08-20
Channels
- # announcements (16)
- # babashka (71)
- # beginners (121)
- # bristol-clojurians (2)
- # calva (55)
- # clj-kondo (16)
- # clojure (103)
- # clojure-europe (9)
- # clojure-italy (5)
- # clojure-nl (4)
- # clojure-spec (49)
- # clojure-uk (57)
- # clojurescript (28)
- # conjure (9)
- # cursive (6)
- # datascript (3)
- # datomic (35)
- # duct (20)
- # events (3)
- # figwheel-main (12)
- # fulcro (6)
- # graalvm (12)
- # juxt (3)
- # kaocha (5)
- # lumo (10)
- # malli (5)
- # off-topic (54)
- # pathom (8)
- # re-frame (19)
- # reitit (21)
- # remote-jobs (1)
- # shadow-cljs (102)
- # sql (38)
- # tools-deps (60)
- # uncomplicate (3)
- # xtdb (10)
Does random-uuid use browser's basic random? Or does it use crypto random APIs if avail?
I see in source it uses rand-int
which uses Math/random
but I'm not sure where that comes from.
Math/random refers to the JS environments https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random
k, so not great randomness then
In .NET there is also a Math module and I am not familiar with Java namespaces. So I wasn't sure if it had something ported from Java with same name Math or if it was using browser version. That tells me what I wanted to know, thanks.
Historically some browsers have not just had poor randomness but downright broken implementations of Math.random. Old versions of Chrome would initially repeat the same number many many times, for example. Collecting info for decisions.
I've used https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues via straight js interop, it's quite simple
they are just meant to be unique more than random (not sure how much of a distinction that is). but when randomness is sketchy it won't be much of either.
in client-server apps, I have the server generate it. but this is client only offline.
previously was using uuid.js when doing this app in F#. https://www.npmjs.com/package/uuid
Probably keep using that.
Is there an idiomatic way to return a vector with 1 or 2 elements, depending on whether the last element is nil or empty?
Something like (into [] (filter (complement empty?) [x y]))
? (not sure if it improves readability, tho)
managed to reduce it down to
(not-empty (filterv some? [x (not-empty y)]))
But not sure how readable that is.
The logical version of it is this
(cond (and (not-empty y)
(some? x)) [x y]
(some? x) [x]
:else nil)
But repeats conditions. nested if is the other optionAssuming x and y are collections, you can do (vec (remove empty? [x y]))
, but that might not produce what you expect if x is also empty. I think the if
version is better.
x is not a collection, it is a keyword that might be nil
Yeah, I went with if
Using if
currently
(if (empty? y)
[x]
[x y])
ended up looking like this:
(when (some? name)
(if-let [params (not-empty path-params)]
(when-let [converted (reduce convert params param-types)]
[name converted])
[name]))
The when
in the middle is not accidental. I want it to return nil if the params cannot be converted.
Thanks all for the help. 🙂