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

Stephen Colebourne scolebourne at joda.org
Fri Mar 8 02:04:37 PST 2013


On 7 March 2013 20:18, Zhong Yu <zhong.j.yu at gmail.com> wrote:
> I'm sensing that you are asking for a factory method mimicing for-loop.
>
> Currently there is a
>
>     static<T> Stream<T> iterate(T seed, UnaryOperator<T> f)
>
> but it's infinite. How about
>
>     static<T> Stream<T> iterate(T init, Predicate<T> p, UnaryOperator<T> f)
>
> For example
>
>     iterate(startDate, d->d.isBefore(endDate), d->d.plusDays(1))

A predicate for ending the infinite loop looks like it could be a
useful API more broadly than JSR-310.

Stephen


More information about the lambda-dev mailing list