On Wed, Mar 03, 2004 at 10:45:57AM -0300, Flavio S. Glock wrote:
> * iterate
>
> This method apply a callback subroutine to all spans of a spanset.
>
> The callback parameter is a DateTime::Span.
>
> sub callback {
> $_[0]->set_time_zone( $tz );
> }
>
> # assign a timezone to the spanset
> $set->iterate( \&callback );
>
> # create a new spanset with the new timezone,
> # $set is unchanged
> $set2 = $set->clone->iterate( \&callback );
>
> If the callback returns undef, the span is removed from the set.
As an immediate reaction from someone who hasn't used any of the
Set/Span modules, I don't like that last part. One, it's too easy for
someone who only skims the documentation to miss it, and end up with a
very subtle bug. Two, lots of functions return undef, so people are
going to end up with ugly code like
$set->iterate( sub { myfunc($_); 1 } );
just to avoid the effect. I think if you want to be able to modify the
set, you should provide different methods for that. ->map and ->grep
come to mind.
I notice that this method with the same undef semantics already exists
in Set, however it is marked experimental, so perhaps it can still
change.
Andrew