[Dbix-class] Improved resultset iterators

Peter Rabbitson rabbit+dbic at rabbit.us
Thu Apr 22 09:00:14 GMT 2010


Toby Corkindale wrote:
> Hey all,
> Wouldn't it be nice if the ResultSet iterators were a bit more advanced?
> 
> I would love it if the iterator built into DBIx::Class supported some
> more functional programming style methods.
> 
> ie. So that I could do:
> 
> $schema->resultset('Users')->search(
>   { first_name => 'Bob' }
> )->foreach(
>   sub { email_user($_) }
> );
> 
> Or to "map" to get the results I want in one hit:
> 
> my @uppercase_names = $schema->resultset('Users')->search(
>   { first_name => 'Bob' }
> )->map(
>   sub { uc($_->last_name . $_->firstname)  }
> );
> 
> Or do a more complex check, grep style, to filter the list:
> 
> my @y_users = $schema->resultset('Users')->search(
>   { first_name => 'Bob' }
> )->grep(
>   sub { return complex_check($_)  }
> );
> 

The implicit iterators built into DBIC resultsets were a blatant design
mistake, and therefore they will not be extended any longer (at least not
in core). You are however welcome to discuss a design for a ResultSet
component, or even contribute to the DBIx::Class::Helpers family of modules.



More information about the DBIx-Class mailing list