Dave Rolsky wrote: > > On Thu, 4 Mar 2004 [EMAIL PROTECTED] wrote: > > > Accepting 'undef' in a map operation is ok, but a Set cannot contain > > 'undef' ! > > The problem is that if the callback is called in a scalar context, and it > does a bare return, like this: > > $set->iterate( sub { return } ) > > then that "return" returns an undef. In fact, I think you don't even need > a bare return. Simply following off the end of the subroutine would do > the trick: > > sub foo { if ( $_[0] > $x ) { ... } } > > so if \&foo were the callback, and the argument wasn't greater than $x, > then it would return undef! > > > So we only have two options if we get an undef: to die, or to discard > > the value. > > I think we need to die and provide a different way to remove elements, > probably a separate method. > > > > 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. > > > > People are already confused with lists vs. sets. > > > > I think using map and grep would lead them to think sets _are_ lists. > > True, but the map/grep analogue would make the functionality obvious. How > about set_grep() and set_map()?
Looks good. How about: * set_map $set2 = $set->set_map( sub { return } ); # same as $set->clone $set2 = $set->set_map( sub { $_[0]->add( hours => 1 ) } ); # returns a new set, which is offset by 1 hour; $set is not modified. $set2 = $set->set_map( sub { $_[0]->add( hours => 1 ); return; } ); # same as before. * set_grep $set2 = $set->set_grep( sub { 1 } ); # same as $set->clone $set2 = $set->set_grep( sub { return } ); # make an empty set $set2 = $set->set_grep( sub { $_[0]->day > 15 } ); # makes a new set, all set elements have day > 15 In DT::Set, $_[0] is a DateTime. In DT::SpanSet, $_[0] is a DateTime::Span. - Flavio S. Glock