Fork me on GitHub
#clojuredesign-podcast
<
2022-03-26
>
leifericf09:03:36

In episode 76, you talk about juxt and “the obvious missing function in core” map-vals. Isn’t that what the new core functions update-vals and update-keys do? The ones that got introduced with Clojure 1.11.0. I haven’t looked, but maybe those use juxt under the hood. Edit: I checked the implementations. They use reduce-kv, not juxt.

nate14:03:12

Yes! The new update-vals is exactly what I was hoping for.

👍 1
nate14:03:12

I think the juxt implementation that I used before is nice to look at, but not at the performance level to be included in core.

nate14:03:02

I liked this comment by fogus about what went into the implementation of update-vals and update-keys and why the approach was different: https://www.reddit.com/r/Clojure/comments/tk6og2/clojure_111_is_now_available/i1rnqp4/

👀 1
leifericf11:03:00

Having listened to episode 77 (about some->) would have helped me when I encountered this problem 😊

nate14:03:32

Oh yeah! I love the some threaders. I just had some code recently where I wanted to check if a (potentially nil) variable was greater than zero and I had this, because pos? is not nil-safe:

(and conflicted (pos? conflicted))
And I realized that I could do this instead:
(some-> conflicted pos?)
I think that reads nicely.

👍 1
leifericf05:03:02

Oh, cool! I was not aware of the pos? function. At first, I read it as “position?” which didn’t make sense. I would have naively checked if the integer was greater than 0 or something like that. Wouldn’t it be possible to use when as well, instead of and or some->? Side-note: As a non-native English speaker, I often get the terms where, when and while mixed up in my mind. For example, when using for, there is both :when and :while, which is a bit confusing to me. It was comforting to hear your guys say how you also get them mixed up sometimes 🙂

nate04:03:52

Yeah, definitely could have used when like this: (when conflicted (pos? conflicted)) which isn't too bad and reads well. The some threaders are a nice way to when your way safely through things that might blow up, which is why I lean on them when I get near a math operation.

👍 1