Welcome! Please see the About page for a little more info on how this works.

0 votes
in Collections by

The vector returned by subvec has not metadata even when the original vector has metadata.

Example:

(meta (subvec 
       (with-meta [0 1 2 3 4 5] {:foo 42})
       0))
;; nil

Expected value:

 {:foo 42}

Live demo here.

1 Answer

0 votes
by

Having thought about it some, I think this is expected behavior. Generally metadata is preserved when using an "update" operation on a collection (assoc, dissoc, conj, disj). In this case, subvec is conceptually creating a new collection that is a subset of the old one (select-keys is maybe another in this category). Because it is a new collection, we would not expect it to get a copy of the metadata from the original.

by
What about the edge case where subvec receives `0` and returns the whole vector?

Also, select-keys preserve metadata.
...