This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-08-14
Channels
- # atom-editor (5)
- # babashka (6)
- # beginners (29)
- # calva (16)
- # cider (1)
- # clj-kondo (20)
- # cljs-dev (44)
- # clojure (29)
- # clojure-europe (19)
- # clojure-nl (8)
- # clojure-norway (7)
- # clojure-spec (2)
- # clojure-sweden (1)
- # clojure-uk (56)
- # clojurescript (32)
- # code-reviews (30)
- # conjure (24)
- # cursive (49)
- # datomic (4)
- # fulcro (31)
- # helix (3)
- # instaparse (4)
- # kaocha (100)
- # lambdaisland (2)
- # mid-cities-meetup (1)
- # monads (1)
- # off-topic (42)
- # pathom (13)
- # pedestal (6)
- # portal (5)
- # re-frame (6)
- # reagent (9)
- # reitit (11)
- # remote-jobs (1)
- # rewrite-clj (11)
- # shadow-cljs (44)
- # sql (22)
- # tools-deps (13)
- # uncomplicate (1)
- # xtdb (15)
Good morning everyone, 👋 I am a new developer who just got his first job working with JS. Thanks to Roam Research I got intrigued by Clojure and intend to explore it further, I struggled to find much Clojurians on Twitter so here I am, and would still love to follow you If you are active there!
Hey, (+ (.-x p) (.-y p))
what is the best way to remove the p
repetition? (+ (->> p (.-x) (.-y)))
is failing for me
> (clojure.walk/macroexpand-all '(+ (->> p (.-x) (.-y))))
(+ (. (. p -x) -y))
I'm not sure there's a good way to get rid of the p
repetition
interesting -
I don't think any answer to that is going to be more readable than what you have
Thanks! Would love to see an alternative, if you have time to burn
something like juxt
is the typical way to apply multiple functions to the same piece of data
but that's bad in multiple ways here
it's way more verbose and it forces boxed numbers which is way slower
(apply + ((juxt #(.-x %) #(.-y %)) p))
something like that
don't be afraid of repetition
Could be a juxt-like macro
then you have to understand the macro
unless you have 10 attributes or something, this is losing in every dimension imo
KISS > DRY every day :)
Yeah, that juxt
alternative above is not readable, unless we are being esoteric and obstructionist
I wouldn’t hate some kind of simple destructuring macro for this. But for this simple example I agree it’s overkill
Well, I can maybe roll my own, because DSL 🙂
I'm building a Clojurescript frontend app and Clojure backed, I can run the frontend separately and the backend but I'm wondering how during dev I can just fire up one instance so that I can test frontend -> backend calls without having to hard code /port:path
in the frontend
the browser's Location object, https://developer.mozilla.org/en-US/docs/Web/API/Location , has enough info to construct a path back to the host the webpage was served from.
May be my question wasn't very clear, in my re-frame app I make calls to my backend /api/users
if I start the repl for the frontend and make those calls they will be mapped to the frontend server+port so
but my backend http server is running on
I could hard code the paths in the frontend, just wondering if there's another way, does this make sense?
you could pass the api end point to the frontend. there's a couple of different ways to do that. the most straight forward is to just dynamically add a script tag like:
<script>window.MY_API_ENDPOINT=" ";</script>
@UM72P2SQM if it's shadow-cljs, then you're probably looking for this: https://shadow-cljs.github.io/docs/UsersGuide.html#dev-http-proxy
What I do is have my backend, your localhost:8080
I believe, serve the static assets and thus, hits the correct endpoints by default. I’m using figwheel and still use that to serve up files updates. Apologies if this wasn’t what you were looking for, just thought I would through this out there.
How would you translate the following into a transducer-based solution, in a way that the map
and filter
is only executed once?
(->> [:foo :bar :baz]
(map str/upper-case)
(filter some?)
first)
I came up with these, but both seem overly cumbersome. (The println
s are just to be able to count iterations.)
(transduce
(comp (map str/upper-case)
(filter some?))
(completing (fn
([] nil)
([result input]
(println "⇒" result input)
(reduced input))))
[:foo :bar :baz])
(first (eduction (comp
(map str/upper-case)
(filter some?)
(fn [rf]
(fn
([] (rf))
([result] (rf result))
([result input]
(println "⇒" result input)
(reduced (rf result input))))))
[:foo :bar :baz]))