Created
June 6, 2013 14:10
-
-
Save Velrok/5721801 to your computer and use it in GitHub Desktop.
Some example code to answer the question of when to move results into a let.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; using a let to store intermediat results | |
(defn recommendations [scores user] | |
(let [user-row (.viewRow (:matrix scores) | |
(get (:row-mapping scores) | |
user)) | |
sorted-by-score (sort-by #(get % 1) | |
(non-zero user-row))] | |
(map (fn [[item, score]] | |
{:item item, :score score}) | |
sorted-by-score))) | |
;; don't use any let | |
(defn recommendations [scores user] | |
(map (fn [[item, score]] | |
{:item item, :score score}) | |
(sort-by #(get % 1) | |
(non-zero (.viewRow (:matrix scores) | |
(get (:row-mapping scores) | |
user)))))) | |
tjg
commented
Jun 6, 2013
Thanks for the comment. I will refactor my code, because this version is very nice.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment