-
-
Save bhenry/91de400e806503b4ba3c to your computer and use it in GitHub Desktop.
This file contains 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
;;a-set1 looks like: | |
({:selected true, :weight 1.0, :text "Yes"} | |
{:selected false, :weight 0.0, :text "No"} | |
{:selected false, :weight -1.0, :text "NA"}) | |
;;;=================== | |
;; is there a better way to avoid two map calls? | |
;;;=================== | |
(defn select-answer [a-set weight] | |
"selects answer by weight returning original a-set if no matching weight" | |
(if (empty? (filter #(= % weight) (map :weight a-set))) | |
a-set | |
(map #(if (= (:weight %) weight) | |
(select-ans %) | |
(deselect-ans %)) a-set))) | |
qa.scorecard> (select-answer a-set1 -3) | |
(#:qa.db.Answer{:text "Yes", :weight 1.0, :selected true} | |
#:qa.db.Answer{:text "No", :weight 0.0, :selected false} | |
#:qa.db.Answer{:text "NA", :weight -1.0, :selected false}) | |
qa.scorecard> (select-answer a-set1 -1) | |
(#:qa.db.Answer{:text "Yes", :weight 1.0, :selected false} | |
#:qa.db.Answer{:text "No", :weight 0.0, :selected false} | |
#:qa.db.Answer{:text "NA", :weight -1.0, :selected true}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment