Fork me on GitHub
#clojure
<
2021-03-29
>
zendevil00:03:53

does a clojure wrapper exist for http://algolia.com client api or at the very least an example usage?

slipset07:03:09

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.

👍 1
adamtait21:04:25

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.

witek10:03:01

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)

flowthing10:03:04

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}]).

3
blak3mill3r17:03:50

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 like

borkdude10:03:54

@witek medley has a function for this called index-by

🙏 1
mpenet13:03:41

why did I wait so long to use meander, it's really nicely done

1
mpenet13:03:19

just turned a soup of core functions to dig into some horrendous json docs into nice patterns

mpenet13:03:51

props to @noprompt

👍 3
1
devn18:03:47

yeah, good stuff.

imre16:03:07

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

imre16:03:49

Couldn't find anything related on ask or jira

imre16:03:56

But perhaps I just wasn't looking hard enough

dpsutton16:03:48

the clojuredocs for proxy have a bit of information about this:

dpsutton16:03:08

> ;; BUG: proxy dispatches only on name, not arity: > ;; ;; You can, however, provide multiple-arity functions to get some support ;; for overloading

ghadi16:03:50

I don't see that GenericObjectPool has a method named destroyObject at all

ghadi16:03:12

ugh, coffee needs to kick in

ghadi16:03:25

you're not proxying GenericObjectPool, but PooledObjectFactory

ghadi17:03:57

what dpsutton said -- proxy dispatches on name (I don't think that this is a bug)

imre17:03:05

Ah, did not notice that on clojuredocs, thanks @U11BV7MTK

imre17:03:16

I'd argue this is a bug though

imre17:03:35

it makes an additive change in a lib breaking

imre17:03:08

which is a pain if the proxy is somewhere you do not control

ghadi17:03:34

good point -- I'm still trying to understand what is happening on 2.9.0 -- I'd expect an arity exception

ghadi17:03:27

ah, nice find

ghadi17:03:31

that explains it

imre17:03:28

@U064X3EF3 would there be a point in posting this to ask.clojure?

alexmiller18:03:43

Could you recap?

alexmiller18:03:05

The general answer to “can I ask a clojure question on http://ask.clojure.org?” Is yes :)

👍 1
imre18:03:15

I found a breakage when bumping a java lib due to how proxy is implemented

ghadi18:03:23

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)

imre19:03:45

looks like the workaround is to use reify

imre19:03:38

while that requires you to define all methods in 2.8.1, the code will continue to work with 2.9.0

imre19:03:16

However it still doesn't help if the proxy call isn't under your control