Fork me on GitHub
#clojure-europe
<
2020-10-08
>
slipset07:10:01

Good morning!

genRaiy08:10:42

Here's twisting you a good morning

otfrom12:10:52

omg, I hate the packaging in R

jasonbell13:10:28

Been ages since I even looked at R packaging.

otfrom13:10:15

does everyone here use rich comment blocks? https://betweentwoparens.com/rich-comment-blocks

3
otfrom13:10:22

(I love them and use them loads)

jasonbell13:10:44

I use rich comments loads though I’m fairly sure that’s down to pairing with you for so long @otfrom

otfrom14:10:57

oh, the damage I've done to you, you poor thing

javahippie13:10:51

I started using them some weeks ago. A commenter on my Twitch streams was very persistent and pushed me to it. Very thankful about that!

jasonbell13:10:38

They are handy to have test script expressions in for the REPL.

borkdude13:10:40

yes, I do use them, typically at the end of a file. at work we prepend it with ;;;; scratch

borkdude13:10:59

clj-kondo also lints them by default, as if they are part of your normal code

borkdude14:10:52

This is one of those "where FP meets the real world" things, where you need to look under the hood to see how things are implemented. Monoids... but please check the source.

genRaiy14:10:17

are you saying this is junk

borkdude14:10:54

no, I'm referring to the built-in one

slipset14:10:53

So, when you see if do you think control-flow or expression?

genRaiy14:10:53

it's slightly annoying that they all circle around the same f'ing name

borkdude14:10:26

@slipset that's a trick question. the only control flow in Clojure is throwing exceptions

slipset14:10:43

Ok, so the thing is that years of java-damage leads me to write code like

(if foo
  (side-effecting-fn! lol)
  (side-effecting-fn! sob))

slipset14:10:04

rather than

(side-effecting-fn! (if (foo lol sob)))

slipset14:10:24

In the first case I use if for control-flow, in the second I use it as an expression.

borkdude14:10:49

Honestly, I think both are fine, in different modes of thinking. Sometimes you're writing a script or task which imperatively does things, at other times you're just building up values.

slipset14:10:56

I find that the latter helps me move difficult code away from the sideffecting code which then makes the difficult code easier to test

3
otfrom14:10:33

yeah, almost all of my refactoring is separating side effecting code from pure

3
borkdude14:10:25

@slipset This is what your talk on ClojureD was also about right

borkdude14:10:38

one of several of these

slipset14:10:39

Mostly, yes

slipset14:10:55

I guess I didn't pick up this example specifically.

slipset14:10:35

Speaking of which. ClojureD was so important for me, knowing how this year turned out.

borkdude14:10:47

Likewise, I'm thankful I could be there

slipset14:10:53

It ended up being this years only conference, and it helped me get on the defn-podcast, which I must say, the recording Saturday-night was one of the best Saturdays this year.

slipset14:10:46

And ClojureD showed how important the community is to me, and and how valuable I think it is to meet you guys IRL.

slipset14:10:27

I guess we're closing in on Thanksgiving 🙂

borkdude14:10:09

🍻 cheers to that

otfrom14:10:04

@borkdude thx to clj-kondo I can't look at https://clojurians.slack.com/archives/CBJ5CGE0G/p1602166804278100 w/o thinking that it should be a when

otfrom14:10:29

unless it was

(side-effecting-fn! (if foo lol sob))

otfrom15:10:12

Hmmm... Hailing in Dundee

otfrom16:10:26

why would I want to use mapv rather than (into []...)?

borkdude16:10:49

@otfrom looking at the source, mapv is implemented using (into [] (map f ...))

borkdude16:10:16

hmm, only when using multiple colls

borkdude16:10:31

I think it comes down to pretty much the same thing

borkdude16:10:07

except when using mapv, you won't create that much garbage (compared to using a lazy seq as the last arg of into)

otfrom16:10:02

do you get an extra lazy seq if your map transducer is doing the work of the f in your mapv?

otfrom16:10:49

(mapv do-my-funky-think my-seq)

vs

(into []
  (map do-my-funky-think)
 my-seq)

borkdude16:10:09

(into [] (map f) coll)
is probably the same-ish as
(mapv f coll)

otfrom16:10:49

so, just a matter of taste then?

borkdude16:10:11

you could try to do some informal perf tests, I expect not to see a difference

otfrom16:10:38

there is always my law (can I say that?) of "you are gonna need to comp in something else eventually"

otfrom16:10:05

YAGNTCINSEE

borkdude16:10:10

you can also use eductions in that case

otfrom16:10:34

I admit that I struggle a bit with when to use eductions

otfrom16:10:44

I'm pretty comfortable with transduce and into

borkdude16:10:58

eductions just couple the transformations with an input source

otfrom16:10:01

but cat, eductions and sequence are things I reach for only occastionally

borkdude16:10:05

and you can do other xforms on top of those

borkdude16:10:29

before realizing it into a target

otfrom16:10:44

not entirely sure I follow how that would be used. Have you got an example you can point me at?

borkdude16:10:38

(def src [1 2 3])
(def ed (eduction (map inc) src))
(def ed2 (eduction (map inc) ed))
(into [] ed2) ;; => [3 4 5]

borkdude16:10:41

in our app we have a SqlReducible, so in the example the src would be a result set from a database

borkdude16:10:50

we can then do some transformations on that, and then read out the result later

borkdude16:10:33

this allows you to just pass the thing around, while not having one giant transducer

💡 3
otfrom16:10:39

ah, I think I know a place in my code where I can use that

otfrom16:10:35

atm, I've got a function that returns a transducer where you pass in some early steps to do the client specific things before you get to the standard flow