This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-09-05
Channels
- # beginners (45)
- # boot (2)
- # cider (2)
- # cljs-experience (1)
- # cljsrn (6)
- # clojure (67)
- # clojure-brasil (1)
- # clojure-dusseldorf (47)
- # clojure-finland (7)
- # clojure-italy (81)
- # clojure-portugal (2)
- # clojure-russia (12)
- # clojure-sanfrancisco (1)
- # clojure-serbia (1)
- # clojure-spec (22)
- # clojure-uk (27)
- # clojurescript (49)
- # clojurewerkz (3)
- # code-reviews (3)
- # component (19)
- # core-async (3)
- # cursive (16)
- # events (7)
- # fulcro (20)
- # graphql (7)
- # immutant (1)
- # jobs (2)
- # juxt (44)
- # leiningen (7)
- # lumo (35)
- # onyx (31)
- # portkey (31)
- # portland-or (8)
- # random (1)
- # re-frame (82)
- # reagent (35)
- # sfcljs (1)
- # spacemacs (5)
- # specter (7)
- # unrepl (4)
- # yada (2)
anybody have any experience with the clojurewerkz buffy framework? I have a point of confusion about dynamic frames and have been scratching my head for a while (tried looking for a specific channel and failed to find one, feel free to point me in the right direction if there is one)
how do I get the ascii value of a character? (I'm sure I've asked this before, but I can't find the old answer)
@alexmiller lol, thanks; I even saw "(int) 'a'" java code, but didn't make the connection to try (int \a)
and char
is the inverse
Interfaces in java just have methods
and for this we have a similar abstraction with defprotocol
Objects in java encapsulates fields
and methods
For is analogous to Object ? can we define a map to just have specific properties ?
you might want to look at defrecord
records are maps with a type and a predefined field set and constructor functions
@alexmiller yeah, defrecord
to be apt
@alexmiller any reason one will use deftype
over defrecord
?
deftype
is a lower-level mechanism so it allows more and provides less. deftypes are not maps and don’t implement any of the map interfaces (it’s up to you to add those in if you want them). deftypes are also able to create mutable fields. In general, you should not use them, unless you need those kinds of capabilities. Also see https://clojure.org/reference/datatypes
I have a ring handler in which I make some HTTP calls. Is there an idiomatic way to always pass on the headers from the ring request into my calls?
preferably curated list, but I will settle with all headers if it makes things simpler
some of the logic I'm doing per HTTP request is being duplicated and I want to abstract it out. It's even happening across projects
You could introduce a layer on top of http/get
(def ^:dynamic *interesting-headers*)
(defn my-get [path]
(http/get path {:headers *interesting-headers*}))
(defn wrap-with-interesting-headers
[h]
(fn [req]
(binding [*interesting-headers* (select-keys (:headers req) ..)]
(h req))))
(def my-handler [req]
(let [foo (my-get "/foo")
bar (my-get "/bar")]
....))
but there i notice you don't include req as an argument. the my-get
starts getting quite convoluted in terms of arguments (especially when I start wondering about callbacks/async)
Yeah, I put the state in a dynamic var instead so that my-get
can retain the same signature as http/get
Regarding the async stuff, are you already using aleph/manifold? If there are a lot of requests, let-flow
lets you combine the results asynchronously
Any simple ways to debounce a function in Clojure?
I’ve only needed it Clojurescript so far, where I could just use the Google Closure library. But I’m not sure how to do that in Java/Clojure land.
@currentoor here’s a decent version that uses core.async, I don’t know if anyone has it in a library though https://gist.github.com/swannodette/5888989
fun fact, on the jvm System/currentTimeMillis (which you might use as a basis of such a debounce function) is, at least on linux, only monotonic on a thread, so once you start running it on multiple threads and comparing the results time can appear to run backwards
nice - here’s a lib that uses timeout instead https://github.com/fullcontact/full.async/blob/master/src/full/async.cljc#L318 - seems like a decent util lib at a first glance actually
I would not pull in core.async for simple functionality like that
@noisesmith thanks. @pesterhazy I agree, I feel like there should be a simpler way. Any alternative suggestions?
@currentoor I'd look into java options (the probably use a different name like RateLimiter http://www.nurkiewicz.com/2012/09/ratelimiter-discovering-google-guava.html ) and failing that implement my own in clojure
where project.clj contains:
:dependencies [[org.clojure/clojure "1.8.0"]
[cheshire "5.8.0"]
is your edn file a top-level map or vector? or is it a series of edn values bare at the top level?
k thanks, is that limitation of edn reader or chesire? initial thoughts were entire map would have to be read in order for chesire to start conversion but had hope i'd be able to pass in input stream
what's the easiest way to wrap another transducer around a channel you get from somewhere
if it’s only being used in one direction, it’s simple enough to wrap it with pipe and put the xf on the other channel
I guess you would have to use pipe twice to wrap both directions
this is trickier than I imagined
=> (def c (>/chan))
#'c
=> (def c' (>/chan 1 (map inc)))
#'c'
=> (>/pipe c c' true)
#object[clojure.core.async.impl.channels.ManyToManyChannel 0x4347c2c7 "clojure.core.async.impl.channels.ManyToManyChannel@4347c2c7"]
=> (>/put! c 1)
true
=> (>/<!! c')
2
* edited for clarityyeah - in any sane situation you only need the one pipe in the apropriate direction
cool I'll look into it
it’s valid to either create your output chan inline, or bind it separately, since pipe returns the output chan