How to copy iterator in Scala?

后端 未结 4 966
星月不相逢
星月不相逢 2021-01-01 17:03

About duplicate

This is NOT a duplicate of How to clone an iterator?

Please do not blindly close this question, all the answers given in so-called

4条回答
  •  感情败类
    2021-01-01 17:19

    You can't duplicate an iterator without destroying it. The contract for iterator is that it can only be traversed once.

    The question you linked to shows how to get two copies in exchange for the one you've destroyed. You cannot keep using the original, but you can now run the two new copies forward independently.

提交回复
热议问题