简体   繁体   English

如何从 Clojure 中的指定点循环遍历集合?

[英]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)?也就是说,如果我有 [“a” “b” “c” “d” “e”] 能够通过指定从第三个 position 开始(或者可能是第二个,如果它需要零索引)?

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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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