Even if 95% of all Iterables are indeed materialised collections that can
be iterated several times, there is nothing in Iterable that requires
implementations to be able to produce more than one Iterator. From the
Javadoc (https://docs.oracle.com/javase/8/docs/api/java/lang/Iterable.html):

Implementing this interface allows an object to be the target of the
"for-each loop" statement.


That's it. I've actually verified this with the community in the past:
http://stackoverflow.com/q/15781739/521799

The accepted answer is has revealed a JDK type that behaves just like
jOOQ's Cursor while implementing Iterable:
https://docs.oracle.com/javase/8/docs/api/java/nio/file/DirectoryStream.html

While I agree that this semantics of "Cursor<R> extends Iterable<R>" can be
confusing in edge cases, the win of being able to use Cursor in a for-each
loop outweighs any doubts. In fact, we've also made ResultQuery a subtype
of Iterable. Both measures allow for an almost PL/SQL style usage of
queries and cursors in for-each loops.

Hope this helps,
Lukas

2014-11-09 10:08 GMT+01:00 Marko Topolnik <[email protected]>:

> Sorry, I have just re-read your below response and there was one thing
> that drew my attention: I was surprised that Cursor could be compatible
> with Iterable since Iterable supports supplying any number of independent
> Iterators. Isn't Cursor stateful such that it always has a current row
> associated with it? This would make it a match for Iterator, but not
> Iterable.
>
> On Friday, September 19, 2014 1:15:58 PM UTC+2, Lukas Eder wrote:
>>
>> Hi Marko,
>>
>> jOOQ currently doesn't support any Java 8 API as we want to maintain
>> backwards compatibility with Java 6 for our customers. However, with jOOQ
>> 3.5, we're going to have Cursor extend Iterable (and perhaps also Iterator)
>> for better interoperability with Java 8 Streams.
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "jOOQ User Group" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups "jOOQ 
User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to