This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-01-22
Channels
- # announcements (2)
- # beginners (42)
- # calva (2)
- # cider (13)
- # clara (2)
- # cljdoc (1)
- # cljs-dev (8)
- # clojure (118)
- # clojure-australia (1)
- # clojure-europe (3)
- # clojure-finland (2)
- # clojure-italy (42)
- # clojure-japan (1)
- # clojure-nl (2)
- # clojure-spec (26)
- # clojure-uk (58)
- # clojurescript (83)
- # cursive (6)
- # data-science (2)
- # datomic (13)
- # devcards (2)
- # duct (9)
- # figwheel-main (4)
- # fulcro (11)
- # graphql (51)
- # jobs (1)
- # juxt (14)
- # kaocha (1)
- # off-topic (24)
- # re-frame (65)
- # reagent (4)
- # reitit (19)
- # remote-jobs (8)
- # shadow-cljs (50)
- # specter (3)
- # speculative (1)
- # vim (5)
- # yada (50)
I noticed the function reitit.coercion/coerce-request
and wonder if it would be more performant to use into
with a transducer instead of reduce-kv
. Did someone already tried?
Like:
(defn coerce-request [coercers request]
(into {}
(fn [k coercer]
[k (coercer request)])
coercers))
@vincent.cantin good catch. I don't think anyone has tried that.
into
is creating a mutable write-only collection in which writing is faster because no new collection is created at each write, then turns it into an immutable at the end of the transducing process.
In theory (some tests are needed though), it could be faster.
Building those 2 node vectors does have some cost
One option is to use transient maps with reduce-kv, but they aren't faster always either
For Clojure JVM, using MapEntry instead of vector might be faster, if using transducer: (clojure.lang.MapEntry. k ...)
... though it is recommended that the class is not used directly
Another option (which I am not sure would make sense as I did not finish to read the full documentation) would be to macro-expand the coercers into a pre-compiled literal Clojure map.
Something like:
(defn request-coercer [coercers]
`(fn coerce-request [request]
{:key1 (~(:key1 coercers) request)
:key2 (~(:key2 coercers) request)
,,,}))
Coercers are set in runtime so macro expansion doesn't work. But it could be possible to "precompile" coercers into coerce-request function as some stage.
is the example at :https://github.com/metosin/reitit/blob/master/examples/ring-swagger/src/example/server.clj outdated? When I browse to the swagger-ui I get the following msg: fetching resource list: undefined; Please wait.
@UDCB49XK3 could you fix the dependencies if they are out-of-sync?