DEV Community

Discussion on: Wormhole - Data Collection Cheat Sheet and Library in 4 Languages

Collapse
 
camdez profile image
Cameron Desautels

I was going to say the same! Here's what that looks like:

(reduce (fn [acc x]
          (+ acc x))
        (range 11))
;; => 55

(reduce (fn [acc x]
          (if (> x 3)
            (reduced acc)
            (+ acc x)))
        (range 11))
;; => 6

So we already have that capability built-in (without introducing a new function). Clojure also already has max-by and min-bymax-key, min-key though, perhaps, with a slightly different interface that what you might have expected.