line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Util::Underscore::ListUtils; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
#ABSTRACT: Interface to List::Util and List::MoreUtils |
4
|
|
|
|
|
|
|
|
5
|
12
|
|
|
12
|
|
55
|
use strict; |
|
12
|
|
|
|
|
14
|
|
|
12
|
|
|
|
|
295
|
|
6
|
12
|
|
|
12
|
|
40
|
use warnings; |
|
12
|
|
|
|
|
12
|
|
|
12
|
|
|
|
|
4274
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
## no critic (ProhibitMultiplePackages) |
9
|
|
|
|
|
|
|
package # hide from PAUSE |
10
|
|
|
|
|
|
|
_; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
## no critic (ProhibitSubroutinePrototypes) |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# this function generates max_by, max_str_by, min_by, min_str_by |
16
|
|
|
|
|
|
|
# It takes the proper comparison operators as arguments. |
17
|
|
|
|
|
|
|
# For max_*: lt, gt |
18
|
|
|
|
|
|
|
# For min_*: gt, lt |
19
|
|
|
|
|
|
|
my $minmax_by = sub { |
20
|
|
|
|
|
|
|
my ($lt, $gt) = @_; |
21
|
|
|
|
|
|
|
## no critic (ProhibitStringyEval) |
22
|
1
|
50
|
33
|
1
|
|
347
|
return eval q~#line ~ . (__LINE__ + 1) . q~ |
|
1
|
50
|
66
|
|
|
6
|
|
|
1
|
0
|
33
|
|
|
4
|
|
|
1
|
0
|
33
|
|
|
2
|
|
|
0
|
50
|
|
|
|
0
|
|
|
0
|
0
|
|
|
|
0
|
|
|
0
|
50
|
|
|
|
0
|
|
|
0
|
100
|
|
|
|
0
|
|
|
0
|
100
|
|
|
|
0
|
|
|
0
|
100
|
|
|
|
0
|
|
|
0
|
50
|
|
|
|
0
|
|
|
0
|
100
|
|
|
|
0
|
|
|
0
|
50
|
|
|
|
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
|
|
|
1
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
21
|
|
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
35
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
345
|
|
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
3
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
20
|
|
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
38
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
4
|
|
23
|
|
|
|
|
|
|
sub (&@) { |
24
|
|
|
|
|
|
|
my $key_func = shift; |
25
|
|
|
|
|
|
|
return if not @_ or not defined wantarray; |
26
|
|
|
|
|
|
|
return $_[0] if not @_ > 1; |
27
|
|
|
|
|
|
|
if (wantarray) { |
28
|
|
|
|
|
|
|
my $max_key = do { |
29
|
|
|
|
|
|
|
local *_ = \$_[0]; |
30
|
|
|
|
|
|
|
$key_func->(); |
31
|
|
|
|
|
|
|
}; |
32
|
|
|
|
|
|
|
my @max_elems = shift; |
33
|
|
|
|
|
|
|
for (@_) { |
34
|
|
|
|
|
|
|
my $key = $key_func->(); |
35
|
|
|
|
|
|
|
next if $key ~ . $lt . q~ $max_key; |
36
|
|
|
|
|
|
|
$max_key = $key if $key ~ . $gt . q~ $max_key; |
37
|
|
|
|
|
|
|
push @max_elems, $_; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
return @max_elems; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
else { |
42
|
|
|
|
|
|
|
my $max_elem = \shift; |
43
|
|
|
|
|
|
|
my $max_key = do { |
44
|
|
|
|
|
|
|
local *_ = $max_elem; |
45
|
|
|
|
|
|
|
$key_func->(); |
46
|
|
|
|
|
|
|
}; |
47
|
|
|
|
|
|
|
for (@_) { |
48
|
|
|
|
|
|
|
my $key = $key_func->(); |
49
|
|
|
|
|
|
|
next if $key ~ . $lt . q~ $max_key; |
50
|
|
|
|
|
|
|
$max_key = $key if $key ~ . $gt . q~ $max_key; |
51
|
|
|
|
|
|
|
$max_elem = \$_; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
return $$max_elem; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
~; |
57
|
|
|
|
|
|
|
}; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
*max_by = $minmax_by->(qw( < > )); |
60
|
|
|
|
|
|
|
*max_str_by = $minmax_by->(qw( lt gt )); |
61
|
|
|
|
|
|
|
*min_by = $minmax_by->(qw( > < )); |
62
|
|
|
|
|
|
|
*min_str_by = $minmax_by->(qw( gt lt )); |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub uniq_by (&@) { |
66
|
4
|
|
|
4
|
|
1746
|
my $key_func = shift; |
67
|
4
|
100
|
|
|
|
13
|
return if not @_; |
68
|
3
|
50
|
|
|
|
6
|
if (not defined wantarray) { |
69
|
0
|
|
|
|
|
0
|
Carp::carp "Useless use of _::uniq_by in void context"; |
70
|
0
|
|
|
|
|
0
|
return; |
71
|
|
|
|
|
|
|
} |
72
|
3
|
100
|
|
|
|
6
|
if (@_ == 1) { |
73
|
1
|
50
|
|
|
|
5
|
return (wantarray) ? @_ : 1; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
# caller context is propagated to grep, so this does the right thing. |
77
|
2
|
|
|
|
|
2
|
my %seen; |
78
|
2
|
|
|
|
|
3
|
grep { not $seen{ $key_func->() }++ } @_; |
|
12
|
|
|
|
|
32
|
|
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub classify (&@) { |
83
|
3
|
|
|
3
|
|
344
|
my $key_func = shift; |
84
|
3
|
100
|
|
|
|
10
|
return if not @_; |
85
|
2
|
50
|
|
|
|
3
|
if (not defined wantarray) { |
86
|
0
|
|
|
|
|
0
|
Carp::carp "Useless use of _::classify in void context"; |
87
|
0
|
|
|
|
|
0
|
return; |
88
|
|
|
|
|
|
|
} |
89
|
2
|
|
|
|
|
3
|
my %categories; |
90
|
2
|
|
|
|
|
3
|
push @{ $categories{ $key_func->() } }, $_ for @_; |
|
12
|
|
|
|
|
34
|
|
91
|
2
|
100
|
|
|
|
18
|
(wantarray) ? %categories : \%categories; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
## no critic (ProtectPrivateVars) |
96
|
|
|
|
|
|
|
$Util::Underscore::_ASSIGN_ALIASES->( |
97
|
|
|
|
|
|
|
'List::Util', |
98
|
|
|
|
|
|
|
reduce => 'reduce', |
99
|
|
|
|
|
|
|
any => 'any', |
100
|
|
|
|
|
|
|
all => 'all', |
101
|
|
|
|
|
|
|
none => 'none', |
102
|
|
|
|
|
|
|
max => 'max', |
103
|
|
|
|
|
|
|
max_str => 'maxstr', |
104
|
|
|
|
|
|
|
min => 'min', |
105
|
|
|
|
|
|
|
min_str => 'minstr', |
106
|
|
|
|
|
|
|
sum => 'sum', |
107
|
|
|
|
|
|
|
product => 'product', |
108
|
|
|
|
|
|
|
pairgrep => 'pairgrep', |
109
|
|
|
|
|
|
|
pairfirst => 'pairfirst', |
110
|
|
|
|
|
|
|
pairmap => 'pairmap', |
111
|
|
|
|
|
|
|
shuffle => 'shuffle', |
112
|
|
|
|
|
|
|
); |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
## no critic (ProtectPrivateVars) |
115
|
|
|
|
|
|
|
$Util::Underscore::_ASSIGN_ALIASES->( |
116
|
|
|
|
|
|
|
'List::MoreUtils', |
117
|
|
|
|
|
|
|
first => 'first_value', |
118
|
|
|
|
|
|
|
first_index => 'first_index', |
119
|
|
|
|
|
|
|
last => 'last_value', |
120
|
|
|
|
|
|
|
last_index => 'last_index', |
121
|
|
|
|
|
|
|
natatime => 'natatime', |
122
|
|
|
|
|
|
|
uniq => 'uniq', |
123
|
|
|
|
|
|
|
part => 'part', |
124
|
|
|
|
|
|
|
each_array => 'each_arrayref', |
125
|
|
|
|
|
|
|
); |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
sub zip { |
128
|
1
|
|
|
1
|
|
4532
|
goto &List::MoreUtils::zip; # adios, prototypes! |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
1; |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
__END__ |