How do I filter elements from a sequence based on indexes

后端 未结 8 1881
慢半拍i
慢半拍i 2021-02-19 10:08

I have a sequence s and a list of indexes into this sequence indexes. How do I retain only the items given via the indexes?

Simple example:

8条回答
  •  既然无缘
    2021-02-19 10:51

    I had a similar use case and came up with another easy solution. This one expects vectors.

    I've changed the function name to match other similar clojure functions.

    (defn select-indices [coll indices]
       (reverse (vals (select-keys coll indices))))
    

提交回复
热议问题