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 tha
Try this...
(second (first (filter (comp (partial some #{"rabble"}) val)
players)))
On Dec 10, 2:40 pm, mudphone 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"
Oops! Slight mistake
(ffirst (filter (comp (partial some #{"rabble"}) val) players))
On Dec 10, 3:27 pm, Sean Devlin wrote:
> Try this...
>
> (second (first (filter (comp (partial some #{"rabble"}) val)
> players)))
>
> On Dec 10, 2:40 pm, mudphone wrote:
>
> > Hi Folks,
>
> > So, I have a sea
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
Thanks for the suggestions.
I think since the original version short circuits when it finds a
result (using "some"), that's probably what I have to stick with.
One thing I didn't mention in the original problem statement is that
my "players" map can be large.
Again, thanks for the ideas.
Kyle
On Dec 11, 10:44 am, mudphone wrote:
> Thanks for the suggestions.
>
> I think since the original version short circuits when it finds a
> result (using "some"), that's probably what I have to stick with.
Sean's solution does as well.
--
You received this message because you are subscribed to
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 wrote:
> Oops! Slight mistake
>
> (ffirst (filter (comp (partial some #{"rabble"}) val) players))
>
> On Dec 10,
ataggart (& sean): Thanks! I over-looked that in my haste to
respond.
lambdatronic: That's a very slick use of "and" in the outer "some!" I
quite like that.
Thanks to all again.
On Dec 11, 5:20 pm, lambdatronic wrote:
> This shaves 7 characters off Sean's solution and short circuits just
> as