Created
June 2, 2012 11:26
-
-
Save koorchik/2857889 to your computer and use it in GitHub Desktop.
List::Util::first bug
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use List::Util qw/first/; | |
| use List::MoreUtils qw/first_value/; | |
| use v5.10; | |
| use Test::More; | |
| is( test('grep'), 4, 'Grep for finding first value' ); | |
| is( test('list_util'), 4, 'List::Util::first for finding first value' ); | |
| is( test('list_more_utils'), 4, 'List::MoreUtils::first_value for finding first value' ); | |
| sub test { | |
| my $mode = shift; | |
| my @array = (1..10); | |
| given ($mode) { | |
| when ('list_util') { | |
| my $first = first { $_ == 4 } @array; | |
| return $first; | |
| } | |
| when ('list_more_utils') { | |
| my $first = first_value { $_ == 4 } @array; | |
| return $first; | |
| } | |
| when ('grep') { | |
| my ($first) = grep { $_ == 4 } @array; | |
| return $first | |
| } | |
| default { | |
| die "wrong test"; | |
| } | |
| } | |
| } | |
| done_testing; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment