On 22/04/10 19:00, Peter Rabbitson wrote:
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.

Hi,
I attach a ResultSet Component that adds the features I was discussing.

Would this be appropriate to release as a mini CPAN module or would you like to incorporate it into something else?

Also, I wondered at which point it is best to call $resultset->reset.. At the start, or end, or both, of all the methods?

Cheers,
Toby

Attachment: Functional.pm
Description: Perl program

_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk

Reply via email to