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)
@witek medley
has a function for this called index-by
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}])
.
why did I wait so long to use meander, it's really nicely done
just turned a soup of core functions to dig into some horrendous json docs into nice patterns
props to @noprompt
yeah, good stuff.
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
https://ask.clojure.org/index.php/10383/using-proxy-might-make-otherwise-additive-change-breaking
Couldn't find anything related on ask or jira
But perhaps I just wasn't looking hard enough
the clojuredocs for proxy have a bit of information about this:
https://clojuredocs.org/clojure.core/proxy#example-542692d4c026201cdc327040
> ;; BUG: proxy dispatches only on name, not arity: > ;; ;; You can, however, provide multiple-arity functions to get some support ;; for overloading
I don't see that GenericObjectPool has a method named destroyObject at all
ugh, coffee needs to kick in
you're not proxying GenericObjectPool, but PooledObjectFactory
what dpsutton said -- proxy dispatches on name (I don't think that this is a bug)
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 likeAh, did not notice that on clojuredocs, thanks @dpsutton
I'd argue this is a bug though
it makes an additive change in a lib breaking
which is a pain if the proxy is somewhere you do not control
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
ah, nice find
that explains it
@alexmiller 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 :)
I found a breakage when bumping a java lib due to how proxy is implemented
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)
looks like the workaround is to use reify
while that requires you to define all methods in 2.8.1, the code will continue to work with 2.9.0
However it still doesn't help if the proxy call isn't under your control