I had a bug a little while ago and not sure if it's something that kondo could detect / warn
(defn any-evens?
[coll]
(reduce (fn [_ x]
(when (even? x)
(reduced true))) false coll))
(any-evens? [2 2])
=> true
(any-evens? [3 3 5])
=> nil
I wanted false in the second case
(defn any-evens?
[coll]
(reduce (fn [_ x]
(if (even? x)
(reduced true)
false)) false coll))
gives the correct results ... I know nil
is falsey but still
Not sure how kondo could help here (in general), as returning nil
is valid in reduce functions.
(defn any-evens?
[coll]
(reduce (fn [_ x]
(even? x)) false coll))
this is also correct, though not as efficient
Why not (some even? ....)
?
I'm trying to check whether using reduced
and not having another part is flaggable
sure, it was a lot more complex in reality so I'm showing a trivial example ... I want to get to the fact that incorrect use of reduced
... forgetting to assign the result to the accumulator was actually the issue
maybe I need a better example