This shaves 7 characters off Sean's solution and short circuits just
as fast:
(some #(and (some #{"rabble"} (val %)) (key %)) players)
Happy hacking!
On Dec 10, 3:29 pm, Sean Devlin <[email protected]> wrote:
> Oops! Slight mistake
>
> (ffirst (filter (comp (partial some #{"rabble"}) val) players))
>
> On Dec 10, 3:27 pm, Sean Devlin <[email protected]> wrote:
>
> > Try this...
>
> > (second (first (filter (comp (partial some #{"rabble"}) val)
> > players)))
>
> > On Dec 10, 2:40 pm, mudphone <[email protected]> wrote:
>
> > > Hi Folks,
>
> > > 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"]
>
> > > })
>
> > > Is there an idiomatic way to search for "rabble" in the vector values,
> > > then return the keyword that matches it? In this example, "rabble"
> > > would match :roger. "b" would match :amit.
>
> > > Currently, I'm doing a "some" which has a predicate function which
> > > contains another "some" seems awkward to me, but works:
>
> > > Assuming the search-str has to be transformed in some way (that I'm
> > > leaving out here), using:
> > > (defn munge-str [search-str]
> > > ... returns a string...)
>
> > > (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))
> > > ))
>
> > > Thanks for any suggestions.
>
> > > Kyle
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en