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?
"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:
(let [s1 s
s2 s]
.....)
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With