Scala: Thread safe mutable lazy Iterator with append <p>For an immutable flavour, <code>Iterator</code> does the job.</p> <pre><code>val x = Iterator.fill(100000)(someFn) </code></pre> <p>Now I want to implement a mutable version of <code>Iterator</code>, with three guarantees:</p> <ul> <li>thread-safe on all transformations(<code>fold</code>, <code>foldLeft</code>, ..) and <code>append</code></li> <li>lazy evaluated</li> <li>traversable only once! Once used, an object from this <code>Iterator</code> should be destroyed.</li> </ul> <p>Is there an existing implementation to give me these guarantees? Any library or framework example would be great. </p> <p><strong>Update</strong></p> <p>To illustrate the desired behaviour.</p> <pre><code>class SomeThing {} class Test(val list: Iterator[SomeThing]) { def add(thing: SomeThing): Test = { new Test(list ++ Iterator(thing)) } } (new Test()).add(new SomeThing).add(new SomeThing); </code></pre> <p>In this example, <code>SomeThing</code> is an expensive construct, it needs to be lazy.</p> <p>Re-iterating over <code>list</code> is never required, <code>Iterator</code> is a good fit.</p> <p>This is supposed to asynchronously and lazily sequence 10 million <code>SomeThing</code> instances without depleting the executor(a cached thread pool executor) or running out of memory.</p>