On 3/15/19 12:16 AM, Stephen Colebourne wrote:
On Thu, 14 Mar 2019 at 19:45, Brian Goetz <brian.go...@oracle.com> wrote:
Why not make `Iterator` implement `IterableOnce`? The default method
would obviously just return `this`.
Such a default would not conform to the contract, as IO requires that
subsequent calls throw.
IterableOnce.wrap(iterator) ?
Not providing some kind of connection between these types will look
pretty silly I think.
Stephen
That makes sense, yes. As a utility method for adapting in situations
where there's an unconsumed Iterator at hand and you have to provide a
"well behaved" IterableOnce. I would call it IterableOnce.of(Iterator)
as it does not really adapt the Iterator, but creates a factory with
provided Iterator. Using this would be preferable to sprinkling ad-hoc
expressions like:
(IterableOnce<T>) () -> iterator
as such IterableOnce instances would not conform to the spec.
Regards, Peter