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

Stephen Colebourne scolebourne at joda.org
Thu Mar 7 11:57:27 PST 2013

This is a call for opinions as to whether JSR-310 should think about
adding stream-based methods.

It seems that the most likely use case is a stream of dates in a
range, either sequential or according to some rule. We already have a
"some rule" type concept in TemporalAdjuster, but that is general,
rather than LocalDate specific, so I've looked at UnaryOperator. One
possible pair of methods would be:

 // methods on LocalDate
 public Stream<LocalDate> datesUntil(LocalDate endDate) {
   return datesUntil(endDate, d -> d.plusDays(1));
 public Stream<LocalDate> datesUntil(LocalDate endDate,
UnaryOperator<LocalDate> generator) {
   // some code to generate a stream checking for being beyond the end date
   // initial perusal suggests this might be a little complex...

 // user code
startDate.datesUntil(endDate, d -> d.plusWeeks(1));
startDate.datesUntil(endDate, d -> d.with(nextHoliday()));

Does the basic stream library support this kind of stuff without
JSR-310 needing to do it?
Does this look useful, or are there other/alternative more useful methods?
Should it only be for dates, or other objects like LocalDateTime or
Would it justify its place in the library given users could just write
a for loop?
Any other thoughts?

BTW, the following code wouldn't work as the user expects:
 startDate.datesUntil(endDate, d -> d.plusMonths(1));
(Jan31 + 1 month = Feb28 ... Feb28 + 1 month = March28!!)


More information about the lambda-dev mailing list