This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-03-29
Channels
- # announcements (8)
- # babashka (41)
- # beginners (45)
- # calva (23)
- # cider (17)
- # cljdoc (2)
- # cljfx (9)
- # clojure (40)
- # clojure-bay-area (13)
- # clojure-czech (4)
- # clojure-europe (46)
- # clojure-germany (6)
- # clojure-nl (13)
- # clojure-serbia (3)
- # clojure-uk (9)
- # clojurescript (76)
- # conjure (7)
- # cursive (5)
- # data-science (6)
- # deps-new (7)
- # fulcro (41)
- # graalvm (2)
- # jobs (6)
- # lsp (10)
- # malli (1)
- # mid-cities-meetup (1)
- # off-topic (77)
- # polylith (40)
- # re-frame (18)
- # releases (1)
- # remote-jobs (9)
- # reveal (1)
- # rewrite-clj (1)
- # shadow-cljs (11)
- # tools-deps (3)
- # tree-sitter (3)
- # vim (8)
- # xtdb (45)
does a clojure wrapper exist for http://algolia.com client api or at the very least an example usage?
They seem to have a REST-api https://www.algolia.com/doc/rest-api/search/ so you should be able to do your own thing with clj-http or some such.
I also need an Algolia wrapper and didn’t find one (at least not one that I liked). Ended up writing my own using their Java lib. Presumably, you could do the same with their JS client (if in CLJS: https://github.com/algolia/algoliasearch-client-javascript). May save you a bit of time over the REST API.
Hi. What is the idiomatic way to collect items from a seqence into a map by id?
(reduce (fn [m item]
(assoc m (:id item) item))
{} items)
If you don't want to pull in a utility library just for that, I think what you're doing is perfectly fine. Another option I've seen quite a lot is (into {} (map (juxt :id identity)) [{:id 1 :b 3} {:id 2 :b 4}])
.
I agree that this is perfectly reasonable code. If you do want to pull in a library that attempts to address this sort of thing more generally, I'd suggest cgrand/xforms
which I use a lot and find very helpful. @witek’s example can be done like this:
(into {} (x/by-key :id x/last) items)
IMO this is easier to understand than the hand-written reduce. It is efficient and also expressive: supposing you only needed the value of the :b
key (not the whole map) you can
(into {} (x/by-key :id :b x/last) items)
Which is functionally equivalent to this:
(into {} (map (juxt :id :b)) items)
xforms is not the only such library, it's just one that I have grown to likejust turned a soup of core functions to dig into some horrendous json docs into nice patterns
Ran into an interesting problem with proxy
-ing an interface which has an overloaded method. Is this known? Repro: https://github.com/imrekoszo/proxy-default
> ;; BUG: proxy dispatches only on name, not arity: > ;; ;; You can, however, provide multiple-arity functions to get some support ;; for overloading
Ah, did not notice that on clojuredocs, thanks @U11BV7MTK
good point -- I'm still trying to understand what is happening on 2.9.0 -- I'd expect an arity exception
According to the fn name it's being swallowed https://github.com/apache/commons-pool/blob/e855619858edd5aae1a6b49788bb7212eb77ec23/src/main/java/org/apache/commons/pool2/impl/GenericObjectPool.java#L679
@U064X3EF3 would there be a point in posting this to ask.clojure?
Could you recap?
The general answer to “can I ask a clojure question on http://ask.clojure.org?” Is yes :)
when a new overloading arity is introduced to existing class's method, an unchanged proxy impl will get ArityException when calling that new signature (provided it originally proxied that method name)