Skip to content

Instantly share code, notes, and snippets.

@Velrok
Created June 6, 2013 14:10
Show Gist options
  • Save Velrok/5721801 to your computer and use it in GitHub Desktop.
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.
;; 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))))))
@Velrok
Copy link
Author

Velrok 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