Fork me on GitHub
#clojure-uk
<
2020-02-18
>
dharrigan05:02:38

Good Morning!

benedek06:02:43

morning. hope otform will rejoin eventually

πŸ‘ 8
marcus08:02:45

Morning guys!

marcus08:02:23

Anyone missing @peterwestmacott 's RCFOTD as much as I do? πŸ˜€

marcus08:02:24

Risking stealing Peter's thunder, and using his own code:

clojure.core/unreduced
([x])
If x is reduced?, returns (deref x), else returns x

πŸ‘ 4
dharrigan08:02:12

nice one!

πŸ™‚ 4
dharrigan08:02:35

How does one feel if I was to create a twitter bot that sent a new function every day?

πŸ‘ 12
marcus08:02:12

I'd love it..

jasonbell08:02:53

Morning

πŸ”” 8
thomas08:02:38

morning...

acron09:02:04

morning all

alexlynham09:02:26

repo for the reframe workshop we ran at lambda lounge mcr yesterday (instrux are in the readme, it’s based off of the default reframe example and is pitched at beginners to clj as well as beginners to reframe, we have a broad range of experience among attendees)

alexlynham09:02:58

the final task we gave 10 mins to complete and pleasingly somebody with clj experience but no reframe got it solved as did a first year CS student who had done some scheme… after some Q&A I think everybody got there. shows the benefit of limiting the scope/ambition of workshops so that all attendees get the basics down I think

Rachel Westmacott09:02:12

That looks nice. I never quite got the hang of reframe so I'm bookmarking that.

dharrigan12:02:57

You know, one of the joys I get from Clojure is the ease on which I can parallelise "things" to split up workload when appropriate, without having to stress about my data structures being fubar'ed πŸ™‚

dharrigan12:02:09

tis rather nice

guy15:02:30

Morning!

guy15:02:24

Has anyone used googles calendar api before? I was thinking about just starting with the java api and going from there

acron17:02:16

Found a valid use for pmap today 😏

πŸ‘ 8
acron17:02:14

Inspired by your inspiration @dharrigan

Gulli17:02:29

Yeah, I'd like to know too

dharrigan17:02:29

I also used pmap, to fire off a couple of long running sql queries

dharrigan17:02:21

(let [workers (pmap #(cleanup-stagnant-data % app-config) [:funky-table-1 :funky-table-2 :funky-table-3])]
    (map #(deref % five-minutes-ms :failure) workers)

dharrigan17:02:07

I'm sure there are multitude of ways of skinning that cat, but this works for me πŸ™‚

seancorfield17:02:38

pmap doesn't return a sequence of futures so that doesn't look right to me...

dharrigan17:02:31

oooh....newbie alert πŸ™‚

dharrigan17:02:48

I sense a rewriting coming on πŸ™‚

dharrigan17:02:26

I'll have to read up on the docs again πŸ™‚

seancorfield17:02:22

(doall (pmap ...)) will realize the whole result. Or you could map a function that does produce a future over a collection and then map deref over that (but you'd still need to force realization).

mccraigmccraig17:02:33

we map over manifold streams for that use-case @dharrigan , and use a buffered-stream to get concurrency control

dharrigan17:02:34

okay, I'll have another go! πŸ™‚

seancorfield17:02:21

And you also have the problem that if the first few elements take a long time, pmap won't necessarily have even started the futures for elements further along the sequence so you don't get the concurrency you might desire anyway πŸ™‚

dharrigan17:02:07

bummer 😞

seancorfield18:02:26

Hence why people say pmap is pretty much always the wrong solution πŸ™‚ And executors are easy to use from Clojure anyway.

marcus18:02:10

And yet, we don't know what was @U052SB76M’s usage of pmap 😁

Gulli18:02:04

Why is your SQL query taking 5 min? 😬

acron20:02:55

Crikey, I didn't even see this thread

acron20:02:43

I am familiar with the advice surrounding pmap (and should probably look at reborg's alternative implementation) but my use case fit the bill so well it was too hard to resist

acron20:02:26

For the record it's some DB queries (n<5) which are all eventually merged into a cache object. Simplified...

(->> queries
     (pmap execute-query)
     (reduce merge))
This fuels some of our server-side HTML rendering. This was previously done using map so switching to pmap was very easy and actually produces a measurable improvement (~100-200ms)

πŸ‘€ 4
marcus18:02:25

I have found today that a keyword, when used as a fn, admits a 2nd argument, exactly like the default value on get.. I found it in something like this:

(defmulti multimethod :my-kw)
(defmethod multimethod :my-val-1 [m n] ,,,)
(defmethod multimethod :my-val-2 [m n] ,,,)

(multimethod {:my-kw :my-val-1} 42)
And for a while I couldn't understand how that was not throwing an exception!! πŸ˜‚
(:my-kw {} :not-found)
=> :not-found
Good to know! πŸ™‚

Vincent Cantin18:02:34

@U9CQCSTUZ You may be already aware of that, but all the following writings are equivalent:

(:my-kw {} :not-found)
({} :my-kw :not-found)
(get {} :my-kw :not-found)

Vincent Cantin18:02:43

Note: this form won’t work when the map is nil however.

(nil :my-kw :not-found)

marcus18:02:31

Oh, wow, yes, of course, maps are fns too! and yeah, then it makes sense the NullPointerException on the last form.. πŸ™‚ Thanks!

dominicm18:02:21

I was frustrated when I found that sets don't do the same

πŸ‘ 4
marcus18:02:54

:thinking_face:

marcus18:02:33

Funny Β―\(ツ)/Β―