On Thu, Mar 04, 2004 at 11:28:20AM -0600, Dave Rolsky wrote:
> Actually, this doesn't encourage it and we _still_ need iterate() for
> sure.  We can have set_map() only be used to create a new set, and
> iterate() only be used to alter the current set in place.

To clarify, do you mean that iterate can be used to alter the current
set in place because you can modify $_[0], or because the return value
of the callback will replace the current element in the set?  Ie, does

    $set->iterate( sub { $_[0]->clone->add( days => 1 ) } );

alter $set?  I think you intend that it would not (in fact, it would
have no effect at all), which is what I would choose.  After all, you
might want to iterate through the set without modifying anything:

    $set->iterate( sub { print $_[0]->hms, "\n" } );

If this is what you mean, then I think that having both ->iterate and
->set_map (as well as possibly ->set_grep) makes perfect sense.

You might argue that the last example is better done with

    foreach ($set->as_list) { ... }

which is a legitimate alternative.  I guess my main point is that
->iterate doesn't sound like it should modify the set (again, unless you
modify $_[0]).  And since modification of $_[0] is always available, I
think it is better not to update the set using the return value of the
callback.

Andrew

Reply via email to