Kurser i Domain-Driven Design - Våren 2012




Tuesday, November 03, 2009

From Java to Clojure, followup followup

Martin Lübcke came up with this solution to the frequency sorting problem presented in the PNEHM article From Java to Clojure:

(defn order-by-freq [coll]
(keys (sort-by #(vector (- (frest %)) (first %)) (frequencies coll))))
Replace frest with fnext for Clojure 1.0.

When it comes to performance, this version is about as fast as the original version in the article, but it sure is compact, and surprisingly readable. Many thanks to Martin!

No comments: