Hi,

Am 10.12.2009 um 20:40 schrieb mudphone:

> So, I have a search string, for example "rabble".  And a map which
> contains keyword keys, and vectors of strings as values:
> 
> (def players
> {
> :amit ["a" "b" "c"]
> :roger ["rabble" "x" "y"]
> })
> 
> (defn key-from-match [search-str]
>  (let [key-of-str? (fn [entry-pair]
>                              (if (some #(= (munge-str search-str) %)
> (val entry-pair))
>                                (key entry-pair)))]
>    (some key-of-str? (players))
>    ))

How about this:

(def players {:amit ["a" "b" "c"]
              :roger ["rabble" "x" "y"]})

(def reverse-players (reduce (fn [rplay [player values]]
                               (into rplay (map vector values (repeat player))))
                             {} players))

(defn key-from-match
  [search-str]
  (reverse-players (munge-str search-str)))

Sincerely
Meikel

Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to