vector?
returns true
if its argument is a vector (implements IPersistentVector
). [:a :b :c :d]
is a vector. So is [[:a :b] [:c :d]]
. Therefore, calling vector?
on either of them will return true
.
Now, we can say a vector is nested if any of its elements is a vector. We can test for this using some
and the vector?
predicate:
(defn nested-vector? [v]
(some vector? v))
This will test specifically for vectors. However, you might want to take a more general approach that applies to any Sequential
data structure:
(defn nested? [coll]
(some sequential? coll))