clojure.core/sort-by 对每个成对比较都会评估 keyfn。当 keyfn 的计算成本较高时,这会变得非常浪费。
`
user=> (def keyfn-calls (atom 0))
user/keyfn-calls
user=> (defn keyfn [x] (do (swap! keyfn-calls inc) x))
user/keyfn
user=> @keyfn-calls
0
user=> (sort-by keyfn (repeatedly 10 rand))
(0.1647483850582695 0.2836687590331822 0.3222305842748623 0.3850390922996001 0.41965440953966326 0.4777580378736771 0.6051704988802923 0.659376178201709 0.8459820304223701 0.938863131161208)
user=> @keyfn-calls
44
`