Possible JSR-310 (date/time API) stream methods

Zhong Yu zhong.j.yu at gmail.com
Fri Mar 8 07:31:57 PST 2013

On Fri, Mar 8, 2013 at 4:14 AM, Stephen Colebourne <scolebourne at joda.org> wrote:
> On 7 March 2013 20:44, Brian Goetz <brian.goetz at oracle.com> wrote:
>> I think a useful mental model for "can I easily make a stream out of this"
>> is "can I easily make an Iterator for this."  (Of course, there are other
>> ways to construct a stream other than an Iterator.)
>> So if you are tempted to write methods that would return an array or a
>> Collection, consider whether instead (or in addition) to return a Stream.
> Which comes back to an earlier question. Why should I return a Stream?
> If I return an Iterator then that is more widely applicable and can be
> converted to a stream is necessary...

On the other hand, a Stream can be converted to an Iterator if necessary.

If a user needs an Iterable, it's not too much trouble either

    Iterable<A> iterable = ()->source.stream().iterator();

That should cover all legacy usages that interface with
Iterable/Iterator. So I agree that new APIs can forget about

Zhong Yu

> Stephen

More information about the lambda-dev mailing list