Fork me on GitHub
#clojure-uk
<
2020-04-07
>
dharrigan06:04:22

Good Morning!

Jakob Durstberger06:04:17

Good morning 🙂

jasonbell07:04:57

Good morning friends.

Adrian Smith08:04:09

Tomorrow evening we're looking at oz and visualisation tools to help make sense of data, no experience needed: https://www.meetup.com/Bristol-Clojurians/events/zdfnqrybcgblb/

alexlynham11:04:36

is that happening remote? How are you doing it? we've been discussing remote options for lambda mcr atm as well :thinking_face:

Adrian Smith11:04:24

we are using https://meet.jit.si/ currently seems ok, I want to test some others at work including http://screen.so

dharrigan15:04:51

Is there a better way of writing this?

dharrigan15:04:06

(def foo {:a nil, :b "bar"})
user=> (into {} (map (fn [[k v]] (if (nil? v) {k ""} {k v}))) foo)
{:a "", :b "bar"}

flefik16:04:45

(reduce-kv (fn [m k v] (assoc m k (or v ""))) foo)

flefik16:04:51

does that work?

Ben Hammond16:04:20

you can give that a bit of syntactic sugar with medley

(medley.core/map-vals #(or % "") foo)

flefik16:04:49

i always thought map-vals and map-keys should be part of clojure.core ..

Ben Hammond16:04:03

mind you I've ALOT of code that I think that about

Ben Hammond16:04:15

and clojure core is pretty busy already

mccraigmccraig16:04:15

i quite like (->> foo (map (fn [[k v]] [k (or v "")])) (into {}))

dharrigan16:04:18

@cfeckardt yes, with a slight change (reduce-kv (fn [m k v] (assoc m k (or v ""))) {} foo)

mccraigmccraig16:04:45

or even (->> (for [[k v] foo] [k (or v "")]) (into {}))

dharrigan16:04:17

all very good choices, but I'm going to stick with core in this instance, no need to pull in medley

dharrigan16:04:25

however! I will add it to my clojure notes for future!

dharrigan16:04:00

I'm still trying to get my head around for. I've used for in the traditional sense, i.e., looping

mccraigmccraig16:04:30

for is quite nifty - i like the cartesian-product thing: (for [a [1 2 3] b [:x :y :z]] [a b]) => ([1 :x] [1 :y] [1 :z] [2 :x] [2 :y] [2 :z] [3 :x] [3 :y] [3 :z])

rickmoynihan16:04:09

I often think zipmap reads quite well for this sort of thing — though not as efficient as reduce-kv due to iterating the k/v’s twice

rickmoynihan16:04:13

(zipmap (keys foo) (->> foo vals (map #(or % ""))))

Ben Hammond16:04:46

is there a 'for' in Python which is like the clojure for ?

Ben Hammond16:04:16

its so different to the Java for that I never really consider it

Ben Hammond16:04:33

why use 'for' when you can use 'map'

rickmoynihan07:04:20

Because it’s really good for doing nested iterations, cartesian products, and also the :when :while :let extensions make more complex stuff easier to read; and prevent excessive indentation. Compare the nested cases of:

(for [x (range 10) 
      y (range 20 30)]
       [x y])
or:
(for [x (range 10)] 
  (for [y (range 20 30)] 
     [x y]))
To the map equivalents:
(mapcat (fn [x]
            (map (fn [y]
                   [x y])
                 (range 20 30)))
          (range 10))

(map (fn [x] 
   (map (fn [y] [x y]) (range 20 30)))
   (range 10))
(appologies for indentation) and you’ll see that in the for case the bindings all align, and the result is cleanly separated from the mechanics of iteration. It’s a macro, so when you need a function map can obviously, or in the thread-last chaining cases.

Ben Hammond16:04:42

unless you are using the funky stuff

mccraigmccraig16:04:50

i vacillate - map is clearly better when you've got a pipeline, but sometimes for just seems cleaner to me

alexlynham19:04:24

double question:

alexlynham19:04:31

what OSX are people currently on

alexlynham19:04:39

what jdk are people currently using

alexlynham19:04:58

kind of thinking of just jumping to 11 since I'm bootstrapping a new laptop

seancorfield19:04:50

macOS 10.12.6 -- because I'm tired of Apple breaking my dev env every time I upgrade (and I'm switching to Windows with my next machine)

seancorfield19:04:39

Adopt OpenJDK 11 in production. Standard OpenJDK 14 locally for testing (and Adopt OpenJDK 8 and 11 as well for matrix testing).

folcon19:04:28

macos 10.14.6, adopt openjdk 13 in general…

alexlynham19:04:57

how are you managing adopt openjdk?

alexlynham19:04:30

I assume not brew, just manually

dharrigan19:04:35

I’m not not Mac, instead Arch Linux. We use Linux almostly exclusively at work. We run OpenJDK 8 and 11 (mostly 11 in Production now)

alexlynham20:04:24

I was using adoptopenjdk8 on my lenovo so I'll push up to 11 LTS on this new machine

alexlynham20:04:32

thanks for the help gang 👍

seancorfield20:04:23

@alex.lynham I just set JAVA_HOME to whichever one I want to use. And I have convenient env vars for the others in my .profile file:

export OPENJDK8_HOME=/Developer/jdk8u232-b09/Contents/Home
export OPENJDK11_HOME=/Developer/jdk-11.0.5+10/Contents/Home
export OPENJDK14_HOME=/Developer/jdk-14.jdk/Contents/Home
export JAVA_HOME=$OPENJDK14_HOME
(looks like I removed the Zulu JDK 8 version at some point -- that was convenient for REBL)

alexlynham20:04:53

Ah okay that makes sense

folcon23:04:45

I did use brew originally, then jenv @alex.lynham