Your main problem here:
(fn [position] ((hash-map (position 0) (map (fn [s] (.substring s 1)) (str/split (position 1)
You create a hash map and then call it as a function (note the double bracket in front of the hash-map ). You can remove it and get the following:
(fn [position] (hash-map (position 0) (map (fn [s] (.substring s 1)) (str/split (position 1)
This validate-lineup method will return
({:c ("4" "4" "3" "3")} {:sg ("6" "11" "6" "6")} {:sf ("7" "5" "5" "5")} {:pf ("3" "1" "1"` "1")} {:pg ("10" "10" "11" "10")})
But you need a single card, not a sequence of cards. You can combine them:
(apply merge (validate-lineup lineup))
Some tips:
Use subs instead of .substring : (fn [s] (subs s 1))
Use destructuring when you iterate over a map
(fn [[key value]] (hash-map key (map (fn [s] (subs s 1)) (str/split value
There is a clear way to create a map from a vector of pairs using the into function. Thus, you can convert lineup to a vector of pairs, where the first element of the pair is the key and the second is a list of numbers:
(defn validate-lineup [lineup] (into {} (map (fn [[key value]] [key (map #(subs s 1) (str/split value #"\|"))]) lineup)))
You can divide b4|b4|b3|b3 into a sequence of re-seq numbers:
user=> (re-seq #"\d+" "b1|b2|b3") ("1" "2" "3")
And finally, you can replace the external map for macro:
(defn validate-lineup [lineup] (into {} (for [[key value] lineup] [key (re-seq #"\d+" value)])))
source share