in reply to List::MoreUtils::first_value() question

Yes; they're the same. Did you want this...?

my $result; first { defined($result = foobar $_) } @list;
package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name

Replies are listed 'Best First'.
Re^2: List::MoreUtils::first_value() question
by tqisjim (Beadle) on Jul 30, 2013 at 16:33 UTC

    The blunt truth is that I'm trying to assemble a body of code to show potential employers. So maybe I should qualify my posts with the following:

    1. Acquiring an essential understanding of CPAN.
    2. Demonstrating best practices.
    3. Initiating best practices.

    That last one requires that I fake it until I make it approach. Your recommendation strikes at the very heart of my metamorphosis.

      Well then a best practice might be to use List::Util::first unless you are already using List::MoreUtils for something else, and not using List::Util for anything, in which case, use List::MoreUtils::firstval.

      I suggest this because it means you'll be sticking to a core module (List::Util), avoiding adding a CPAN dependency. However, if you're already using the CPAN dependency, and you're not using List::Util in the module, then there's no reason to use both modules; stick with List::MoreUtils.

      I say "might", because there are always "it depends" criteria, and best practices suggestions are rarely as simple as "just do it this way."


      Dave