--
You received this message because you are subscribed to the Google Groups "scala-internals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-interna...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
val (ita, itb) = it.duplicateHi Viktor (and Erik and Haoyi),val it = myCollection.iterator.filter(p)
That's what I thought at first too, but maybe I didn't make the counterargument clear enough (i.e. the one that made me wonder).
On Tue, Dec 30, 2014 at 8:40 PM, Rex Kerr <ich...@gmail.com> wrote:val (ita, itb) = it.duplicateHi Viktor (and Erik and Haoyi),val it = myCollection.iterator.filter(p)
That's what I thought at first too, but maybe I didn't make the counterargument clear enough (i.e. the one that made me wonder).What happens if you use `it` after this line?
val (a, b) = (Future(foo(ita)), Future(bar(itb)) // Horrible breakage ensuesval (ita, itb) = it.duplicateHi Viktor (and Erik and Haoyi),val it = myCollection.iterator.filter(p)
That's what I thought at first too, but maybe I didn't make the counterargument clear enough (i.e. the one that made me wonder).
On Tuesday, December 30, 2014 11:40:40 AM UTC-8, Rex Kerr wrote:val (a, b) = (Future(foo(ita)), Future(bar(itb)) // Horrible breakage ensuesval (ita, itb) = it.duplicateHi Viktor (and Erik and Haoyi),val it = myCollection.iterator.filter(p)
That's what I thought at first too, but maybe I didn't make the counterargument clear enough (i.e. the one that made me wonder).
if foo() races far ahead of bar(), could this produce an OOM? Doesn't duplicating an arbitrary iterator imply buffering? An iterator could have unbounded elements.
val c = myCollection.withFilter(p)
val ita = c.iterator
val itb = c.iterator
or the equivalent would be more sane if so. If it buffers, I feel the best thing is to remove it entirely -- it does not fit well with the concept of mutable iterators if it implies potentially unbounded buffering. Although iterators carry state, users generally expect their state to be small and bounded. Some implementations (such as an iterator for an IndexedSeq) could avoid the buffering, but in general this seems dangerous for arbitrary iterators rather than specific subtypes of iterators where this would be safer.
--
You received this message because you are subscribed to the Google Groups "scala-internals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-interna...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
On Tuesday, December 30, 2014 11:40:40 AM UTC-8, Rex Kerr wrote:val (a, b) = (Future(foo(ita)), Future(bar(itb)) // Horrible breakage ensuesval (ita, itb) = it.duplicateHi Viktor (and Erik and Haoyi),val it = myCollection.iterator.filter(p)
That's what I thought at first too, but maybe I didn't make the counterargument clear enough (i.e. the one that made me wonder).
if foo() races far ahead of bar(), could this produce an OOM? Doesn't duplicating an arbitrary iterator imply buffering?
If it buffers, I feel the best thing is to remove it entirely -- it does not fit well with the concept of mutable iterators if it implies potentially unbounded buffering.
Perhaps `duplicate` should be deprecated instead?
If you want that kind of behavior* you may as well do:
val (it1, it2) = { val v = it.toVector; (v.iterator, v.iterator) }
(* I've only been programming for 20-odd years and I've never had the "Iterator.duplicate" use-case yet)
On Tue, Dec 30, 2014 at 1:05 PM, Viktor Klang <viktor...@gmail.com> wrote:Perhaps `duplicate` should be deprecated instead?
If you want that kind of behavior* you may as well do:
val (it1, it2) = { val v = it.toVector; (v.iterator, v.iterator) }Welllll, this necessarily instead of only potentially buffers the entire iterator.
(* I've only been programming for 20-odd years and I've never had the "Iterator.duplicate" use-case yet)Yeah, me too. And, me too. (Caveat: I don't recall using an iterator at all in Turbo Pascal. Second caveat: I guess duplicating pointers to walk a singly-linked list in C++ doesn't count.)
But I have used partition and span. And they have the thread-unsafety problem, which I should at least document.
--Rex--
You received this message because you are subscribed to the Google Groups "scala-internals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-interna...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
> I think we're better off allowing these operations but documenting the potential pitfalls, since these things are useful.I'd argue the opposite; that scala's collections have too many "useful but full of pitfalls" things, and that the API in general needs to be smaller.
When you have so many methods that nobody knows what is safe and what isn't, that's as good as not having them =/ What good is "necessarily" vs "potentially" if nobody really knows what the current implementation is doing?
I know most of the methods on Iterator are basically off-limits to me because I can never be sure when It'll do something stupid and I'll have to put in a .toSeq anyway.