Michael Ninh
Michael Ninh

Reputation: 802

Remove string instances from collection

I have this collection

("string" {:1 a} "string" {:2 b} "string")

I want to only return elements that are maps.

As so,

({:1 a} {:2 b})

Upvotes: 2

Views: 112

Answers (2)

ntalbs
ntalbs

Reputation: 29448

If your intention is to remove strings in the list, you use remove and sting? predicate. This is pretty straightforward.

user=> (remove string? '("string" {:1 a} "string" {:2 b} "string"))
({:1 a} {:2 b})

If your intention is to remove elements other than map, then you'd better use filter and map? predicate, as in @Reut's answer.

Upvotes: 8

Reut Sharabani
Reut Sharabani

Reputation: 31339

Using filter maybe?

(filter map? coll)

Output:

({:1 3} {:2 4})

Upvotes: 6

Related Questions