clojure

New to Clojure? Try the #beginners channel. Official docs: https://clojure.org/ Searchable message archives: https://clojurians-log.clojureverse.org/
zendevil 2021-03-29T00:44:53.048300Z

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

slipset 2021-03-29T07:00:09.049300Z

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
adamtait 2021-04-06T21:24:25.126300Z

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.

witek 2021-03-29T10:24:01.051200Z

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)

borkdude 2021-03-29T10:24:54.051500Z

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

πŸ™ 1
flowthing 2021-03-29T10:37:04.052200Z

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
mpenet 2021-03-29T13:55:41.059Z

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

βž• 1
mpenet 2021-03-29T13:56:19.059700Z

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

mpenet 2021-03-29T13:56:51.060Z

props to @noprompt

πŸ‘ 3
1
devn 2021-03-31T18:55:47.151Z

yeah, good stuff.

imre 2021-03-29T16:51:07.062Z

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

imre 2021-03-29T16:54:49.062200Z

Couldn't find anything related on ask or jira

imre 2021-03-29T16:55:56.062400Z

But perhaps I just wasn't looking hard enough

dpsutton 2021-03-29T16:56:48.062600Z

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

dpsutton 2021-03-29T16:57:08.063Z

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

ghadi 2021-03-29T16:58:50.063200Z

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

ghadi 2021-03-29T16:59:12.063600Z

ugh, coffee needs to kick in

ghadi 2021-03-29T16:59:25.063800Z

you're not proxying GenericObjectPool, but PooledObjectFactory

ghadi 2021-03-29T17:00:57.064Z

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

blak3mill3r 2021-03-29T17:05:50.064300Z

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

imre 2021-03-29T17:15:05.064800Z

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

imre 2021-03-29T17:15:16.065Z

I'd argue this is a bug though

imre 2021-03-29T17:15:35.065200Z

it makes an additive change in a lib breaking

imre 2021-03-29T17:16:08.065500Z

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

ghadi 2021-03-29T17:20:34.065700Z

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

ghadi 2021-03-29T17:46:27.066200Z

ah, nice find

ghadi 2021-03-29T17:46:31.066400Z

that explains it

imre 2021-03-29T17:56:28.066600Z

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

alexmiller 2021-03-29T18:15:43.067100Z

Could you recap?

alexmiller 2021-03-29T18:19:05.068300Z

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

πŸ‘ 1
imre 2021-03-29T18:20:15.068500Z

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

imre 2021-03-29T18:20:27.068700Z

https://github.com/imrekoszo/proxy-default

ghadi 2021-03-29T18:42:23.069200Z

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)

imre 2021-03-29T19:03:45.069400Z

looks like the workaround is to use reify

imre 2021-03-29T19:05:38.069700Z

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

imre 2021-03-29T19:44:16.070Z

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