This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2015-10-09
Channels
- # admin-announcements (9)
- # boot (114)
- # cider (15)
- # cljs-dev (10)
- # clojure (35)
- # clojure-boston (5)
- # clojure-dev (39)
- # clojure-greece (1)
- # clojure-japan (10)
- # clojure-nl (3)
- # clojure-poland (2)
- # clojure-russia (10)
- # clojure-sg (8)
- # clojure-switzerland (1)
- # clojure-uk (34)
- # clojurescript (76)
- # clojurescript-ios (3)
- # clojurewerkz (1)
- # clojurex (9)
- # cursive (3)
- # datomic (1)
- # devcards (137)
- # emacs (5)
- # events (1)
- # hoplon (99)
- # jobs (1)
- # ldnclj (50)
- # off-topic (1)
- # om (3)
- # onyx (10)
- # re-frame (4)
- # reagent (1)
- # ring-swagger (15)
- # yada (35)
hi, should I use (while true …)
or (loop [] … (recur))
for an infinite loop? I think the main difference is the ability to end the loop, but since it’s supposed to be infinite…
you could also use recur over a function calls
zatz even beta
Hello I am looking for a way to measure response times of my compojure server. I am thinking about writing a middleware in it. Is there a clojure function for this kind of timers ?
nha: https://clojuredocs.org/clojure.core/time might be an option. wrap it in with-out-str, and send the string off to be analyzed.
I'm confused as to why transduce
requires that the reducing fn also have an arity of 1. I thought the reducing fn would be identical to the one used with reduce
.
jrychter: to produce the terminating value, i think
i remember Rich Hickey discussing this in one of his transducer talks - the internals one, i believe
it was something like that. i could be way off. i know there’s a good reason, though
Hmm. It's difficult to find an example, because everybody uses +
as a reducing function. I'm assuming the arity-1 function is supposed to just return the argument…
@jrychter: see “Creating Transducers” here. partition-all
is an example that has to flush its intermediate collection.
that section also points to [`completing`](http://clojure.github.io/clojure/clojure.core-api.html#clojure.core/completing) which will add a completing arity to a reducing fn without one, default case being nothing to be done (identity).
@sander you might look at doto
it's really designed for calling side-effecting interop calls, but would work here too I think
@alexmiller: thanks! tap
has side effects so it fits well
(doto v f) is what you have above for example (invokes (f v) and returns v)
(doto (chan) #(tap my-mult %))
would be the equivalent to yours - it threads the first value into the first arg position like ->
@jrychter, @robert-stuttaford The reducing function arities are
`(fn ([] ...return initial value...)
(fn
([] ... return initial value ...)
([accumulator] ... complete the accumulated value ...)
([accumulator input] ... add input to accumulated value ...))
@bkamphaus: thanks!
Ok, I see now. The documentation for transduce could use @stuartsierra 's example.
thanks for the ping!
@jrychter: an example would be a reducing function building a string and internally using a StringBuffer during the reduction as a performance enhancement, (StringBuffer.) in the 0-arity, (.toString acc) in the 1-arity and (.append acc i) in the 2-arity
clojure.data/diff
: has someone come up already with a way to get all the paths that have changed, like [[:here :there 5][;here :too][:there :so 4 4]]
?
It kind of upsets me how many tools/products still configure using their code DSL rather than just shipping data. Totally prevalent
I'm feeling dirty 😞 seems like I'm punching clojure's face 😞 could anyone tell me if the code below is idiomatic or not
(defn chain [context funcs success-handler error-handler]
(let [chain (apply comp (reverse funcs))]
(try (success-handler (chain context))
(catch Throwable e
(error-handler e)))))
(defn create-account-success [result]
{:body result :status 201})
(defn create-account-error-handling [params]
(println (str "failed " params))
{:body "Create accounts failed !" :status 400})
(defn create [account]
(chain account
[ account/validate
account/create<!]
create-account-success
create-account-error-handling))