clj-kondo

James Amberger 2024-08-17T23:46:35.451629Z

• What do you think of a linter that warns against using the (reduce f coll) sig of reduce?

💯 1
✅ 2
seancorfield 2024-08-18T17:36:57.241429Z

Oh, I should turn this on at work! 🙂

2024-08-18T20:17:56.114189Z

> Who knows what the semantics of reduce are when you call it with a collection and no initial value? - https://github.com/matthiasn/talk-transcripts/blob/master/Hickey_Rich/InsideTransducers.md I remembered what reduce does without an init, do I get a prize? Or maybe therapy? 😉

James Amberger 2024-08-18T20:23:03.029689Z

thanks

seancorfield 2024-08-19T18:23:29.372649Z

I turned this on and it found two reduce calls without an init value. Not bad in 146k lines of code, with some of it dating back over a decade!

👍 2
2024-08-19T20:08:23.793759Z

TIL eductions don't implement IReduce

user=> (reduce + (eduction (map #(do (prn %) %)) (range 10)))
Execution error (ClassCastException) at user/eval3 (REPL:1).
class clojure.core.Eduction cannot be cast to class clojure.lang.IReduce (clojure.core.Eduction and clojure.lang.IReduce are in unnamed module of loader 'app')
user=> (reduce + 0 (eduction (map #(do (prn %) %)) (range 10)))
0
1
2
3
4
5
6
7
8
9
45

seancorfield 2024-08-19T20:20:09.427149Z

I made that same choice when I implemented next.jdbc/plan (`IReduceInit` only) so that users have to think about the base case and make an appropriate choice 🙂

👍 2
borkdude 2024-08-18T06:15:02.884639Z

AFAIK this already exists, but maybe off by default, I’ll check for the link when I’m not afk