On Thu, 6 Mar 2003, fglock wrote:

> This is an idea to make extensible iterators.
>
> SYNOPSIS
>
>     $iter_user = DateTime::Iterator (
>         truncate => sub { ..... },
>         next => sub { ..... },
>         previous => sub { ..... },
>     );

I take it these subs would do something like receive the current datetime
object and then return a new one?

>     $dt->next( $iter_user );
>     $dt->previous( $iter_user );
>     $dt->truncate( $iter_user );

I'm not sure I like the idea of creating an iterator object and then not
actually using it directly.  I also don't particularly like to the idea of
having one iterator contain multiple code references.  It should just do
one thing.

What about ...

 my $iter = DateTime::Iterator->new( datetime => $dt,
                                     iterator => sub { ... },
                                   );

 # next does not mean "a later datetime" here, just the next in the
 # iteration.
 my $next_dt = $iter->next;

For many uses, this would be sufficient:

 my $iter = DateTime::Iterator->new( datetime => $dt,
                                     duration =>
                                     DateTime::Duration->new( days => 1 ),
                                   );

>     $dt->next( 'day' );
>     $dt->previous( 'day' );
>     $dt->truncate( 'day' );

I definitely don't think of truncation as related to iteration.  The two
have basically nothing in common.

Back when I started this project, I was thinking that iterators would be
produced by sets, so that we might have this:

 my $set = DateTime::Set->new( recurrence => sub { ... },
                               start => $dt );

 my $iter = $set->iterator;

 while ( my $dt = $iter->next ) { ... }

I still like this API.  What do others think?



-dave

/*=======================
House Absolute Consulting
www.houseabsolute.com
=======================*/

Reply via email to