简体   繁体   中英

How do I cycle over a collection from a specified point in Clojure?

How would a cycle over a collection but start at different specified points in that collection? That is, if I had [“a” “b” “c” “d” “e”] be able to start the cycle at, say, “c” by specifying to start at the third position (or perhaps second, if it needs to be zero indexed)?

You can drop a few elements from a collection that cycles over:

user=> (def elems [:a :b :c :d :e])
#'user/elems

user=> (->> elems cycle (drop 2) (take 10))
(:c :d :e :a :b :c :d :e :a :b)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM