How can I lazily “clone” a seq in Clojure. Something along the lines of
(let [[s1 s2] (clone-seq s)]
...)
such that s1 and s2 are independent seqs backed by s?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
“cloning” a seq feels wrong to me: in normal Clojure usage you would expect seqs to be immutable, so it should be perfectly fine to just do something like:
If your seqs are mutable or have some kind of side effects when they are traversed, then you are likely to run into problems for different reasons: mutable seqs tend not to be a good fit for a functional language like Clojure. You’ll run into all sorts of odd issues: do you want the side effects to happen twice when you “clone” a seq for example? Do you need a deep clone of all the contents as well?