blib/lib/Acme/IEnumerable.pm

filter: Statementstmt 32.9% 141 / 428 Branchbran 9.8% 12 / 122 Conditioncond 0.0% 0 / 14 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 37.6% 41 / 109 Podpod 6.2% 2 / 32 totaltotal 27.4% 196 / 714 CC 67 SCAR 20.1
CC
67
Cov
27%
aggregate
30.0
__ANON__
20.0
__ANON__
20.0
CRAP 7.5
↑ Summary
1 package Acme::IEnumerable;
2 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
5
6 4 ▶use vars qw{ $VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS };
Subroutine BEGIN: called CC=1 SCAR=0.0
7
8 4 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 @ISA = qw(Exporter);
10 4 %EXPORT_TAGS = ( 'all' => [ qw(
11 ) ] );
12
13 4 @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
14 4 @EXPORT = @EXPORT_OK;
15 4 $VERSION = '0.6';
16 };
17
18 #####################################################################
19 #
20 #####################################################################
21 package Acme::IEnumerable::List;
22 4 ▶use base qw/Acme::IEnumerable/;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 4 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 4 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
27
28 3 ▶sub _create {
Subroutine _create: called CC=1 SCAR=0.0
29 bless {
30 _list => $_[0],
31 _zero => 0,
32 3 _last => scalar(@{ $_[0] }) - 1,
33 _dir => 1,
34 _new => $_[1],
35 }, __PACKAGE__;
36 }
37
38 8 ▶sub count {
Subroutine count: called CC=1 SCAR=0.0
39 8 my ($self) = @_;
40 8 $self->{_dir} * ($self->{_last} - $self->{_zero}) + 1;
41 }
42
43 3 ▶sub element_at {
Subroutine element_at: called CC=3 SCAR=11.3
44 3 my ($self, $index) = @_;
45 3 ▶ Carp::cluck unless defined $index;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $index 0 3 3
46 3 ▶ croak unless $self->count > $index;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->count > $index 0 3 3
47 3 my $projected = $self->{_zero} + $index * $self->{_dir};
48 3 $self->{_list}->[$projected];
49 }
50
51 0 ▶sub last {
Subroutine last: not called CC=2 SCAR=17.9
52 0 my ($self) = @_;
53 0 ▶ croak unless $self->count;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->count 0 0 0
54 0 $self->element_at($self->count - 1);
55 }
56
57 0 ▶sub last_or_default {
Subroutine last_or_default: not called CC=2 SCAR=17.9
58 0 my ($self, $default) = @_;
59 0 ▶ return $default unless $self->count;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->count 0 0 0
60 0 $self->element_at($self->count - 1);
61 }
62
63 0 ▶sub first {
Subroutine first: not called CC=2 SCAR=17.9
64 0 my ($self) = @_;
65 0 ▶ croak "No elements for 'first'" unless $self->count;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->count 0 0 0
66 0 $self->element_at(0);
67 }
68
69 0 ▶sub first_or_default {
Subroutine first_or_default: not called CC=2 SCAR=17.9
70 0 my ($self, $default) = @_;
71 0 ▶ return $default unless $self->count;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->count 0 0 0
72 0 $self->element_at(0);
73 }
74
75 3 ▶sub from_list {
Subroutine from_list: called CC=1 SCAR=0.0
76 3 my $class = shift;
77 3 my @list = @_;
78 2 ▶ return _create \@list, sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
79 8 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
80 8 state $index = 0;
81 8 ▶ return unless $index <= $#list;
Branch: 1 branch
BranchTrueFalseTotal
unless $index <= $#list 2 6 8
82 6 return \($list[$index++]);
83 2 };
84 3 };
85 }
86
87 0 ▶sub skip {
Subroutine skip: not called CC=1 SCAR=6.9
88 0 my ($self, $count) = @_;
89 0 ▶ return Acme::IEnumerable::_create(sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
90 0 ▶ return sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
91 0 state $index = $count;
92 0 ▶ return unless $index < $self->count;
Branch: 1 branch
BranchTrueFalseTotal
unless $index < $self->count 0 0 0
93 0 return \($self->element_at($index++));
94 0 };
95 0 });
96 }
97
98 1 ▶sub reverse {
Subroutine reverse: called CC=2 SCAR=6.9
99 1 my ($self) = @_;
100
101 1 ▶ return $self->to_list unless $self->count;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->count 0 1 1
102
103 1 my $new;
104 $new = bless {
105 _list => $self->{_list},
106 _last => 0,
107 1 _zero => scalar(@{ $self->{_list} }) - 1,
108 _dir => -1,
109 1 ▶ _new => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
110 4 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
111 4 state $index = 0;
112 4 ▶ return unless $index < $new->count;
Branch: 1 branch
BranchTrueFalseTotal
unless $index < $new->count 1 3 4
113 3 return \($new->element_at($index++));
114 }
115 1 },
116 1 }, __PACKAGE__;
117 }
118
119 #####################################################################
120 #
121 #####################################################################
122 # sub find { ... }
123 # sub find_index { ... }
124 # sub find_last { ... }
125 # sub find_last_idex { ... }
126 # sub exists { ... }
127 # sub find_all { ... }
128 # sub binary_search { ... }
129 # sub index_of { ... }
130 # sub last_index_of { ... }
131
132 4 1;
133
134 #####################################################################
135 #
136 #####################################################################
137 package Acme::IEnumerable::Ordered;
138 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
139 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
140 4 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
141 4 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
142 4 ▶use base qw/Acme::IEnumerable/;
Subroutine BEGIN: called CC=1 SCAR=0.0
143
144 1 ▶sub _create {
Subroutine _create: called CC=1 SCAR=0.0
145 1 bless {
146 _key => $_[0],
147 _sgn => $_[1],
148 _par => $_[2],
149 _new => $_[3],
150 }, __PACKAGE__;
151 }
152
153 0 ▶sub order_by {
Subroutine order_by: not called CC=1 SCAR=6.9
154 # This assumes to_enumerable will remove the ::Ordered base type
155 0 my ($self) = @_;
156 0 $self->to_enumerable->order_by(@_);
157 }
158
159 0 ▶sub order_by_descending {
Subroutine order_by_descending: not called CC=1 SCAR=6.9
160 # This assumes to_enumerable will remove the ::Ordered base type
161 0 my ($self) = @_;
162 0 $self->to_enumerable->order_by_descending(@_);
163 }
164
165 0 ▶sub then_by_descending {
Subroutine then_by_descending: not called CC=1 SCAR=6.9
166 0 _then_by(@_[0..1], -1);
167 }
168
169 1 ▶sub then_by {
Subroutine then_by: called CC=1 SCAR=0.0
170 1 _then_by(@_[0..1], 1);
171 }
172
173 1 ▶sub _then_by {
Subroutine _then_by: called CC=1 SCAR=0.1
174 1 my ($self, $key_extractor, $sign) = @_;
175 1 ▶ return _create $key_extractor, $sign, $self, sub {
Subroutine __ANON__: called CC=4 SCAR=14.2
176 1 my $top = $self;
177 1 my @ext = $key_extractor;
178 1 my @sgn = $sign;
179 1 ▶ for (my $c = $self; $c->isa(__PACKAGE__); $c = $c->{_par}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->isa(__PACKAGE__)) 0 1 1
180 0 $top = $c;
181 0 unshift @ext, $c->{_key};
182 0 unshift @sgn, $c->{_sgn};
183 }
184 1 my @list = $top->to_perl;
185
186 # This is not written with efficiency in mind.
187 my @ordered = sort {
188 1 my $cmp = 0;
189 3 ▶ for (my $ix = 0; $ix < @ext; ++$ix) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ix < @ext) 3 0 3
190 3 my $ext = $ext[$ix];
191 3 my $k1 = do { local $_ = $a; $ext->($_) };
192 3 my $k2 = do { local $_ = $b; $ext->($_) };
193 3 $cmp = $sgn[$ix] * ($k1 <=> $k2);
194 3 ▶ last if $cmp;
Branch: 1 branch
BranchTrueFalseTotal
if $cmp 3 0 3
195 };
196 3 return $cmp;
197 } @list;
198
199 1 return Acme::IEnumerable->from_list(@ordered)->new;
200 1 };
201 }
202
203 4 1;
204
205 #####################################################################
206 #
207 #####################################################################
208 package Acme::IEnumerable::Grouping;
209 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
210 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
211 4 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
212 4 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
213 4 ▶use base qw/Acme::IEnumerable::List/;
Subroutine BEGIN: called CC=1 SCAR=0.0
214
215 0 ▶sub from_list {
Subroutine from_list: not called CC=1 SCAR=6.9
216 0 my $class = shift;
217 0 my $key = shift;
218 0 my $self = Acme::IEnumerable->from_list(@_);
219 0 $self->{key} = $key;
220 0 bless $self, __PACKAGE__;
221 }
222
223 0 ▶sub key { $_[0]->{key} }
Subroutine key: not called CC=1 SCAR=6.9
224
225 4 1;
226
227 #####################################################################
228 #
229 #####################################################################
230 package Acme::IEnumerable;
231 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
232 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
233 4 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
234 4 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
235
236 4 do {
237 4 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
238 4 *from_list = \&Acme::IEnumerable::List::from_list;
239 4 *to_array = \&Acme::IEnumerable::to_perl;
240 4 *order_by = \&Acme::IEnumerable::Ordered::then_by;
241 4 *order_by_descending =
242 \&Acme::IEnumerable::Ordered::then_by_descending;
243 };
244
245 0 ▶sub _create {
Subroutine _create: not called CC=1 SCAR=6.9
246 0 bless {
247 _new => $_[0],
248 }, __PACKAGE__;
249 }
250
251 4 ▶sub new { $_[0]->{_new}->() }
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
252
253 0 ▶sub range {
Subroutine range: not called CC=2 SCAR=17.9
Pod documented
254 0 my ($class, $from, $count) = @_;
255
256 0 ▶ if (defined $count) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $count) 0 0 0
257 # ...
258 }
259
260 0 ▶ return _create sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
261 0 ▶ return sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
262 0 ▶ state $counter = $from // 0;
Condition0%0/2
$from // 0
l!l
00
MC/DC0%0/1
$from // 0
$from
Truth table0%0/2
A
A= $from
Aresult
11
00
263 0 return \($counter++);
264 0 };
265 0 };
266 }
267
268 0 ▶sub take {
Subroutine take: not called CC=1 SCAR=6.9
Pod documented
269 0 my ($self, $count) = @_;
270 0 ▶ return _create sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
271 0 ▶ return sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
272 0 state $left = $count;
273 0 ▶ return unless $left;
Branch: 1 branch
BranchTrueFalseTotal
unless $left 0 0 0
274 0 $left--;
275 0 state $base = $self->new();
276 0 my $item = $base->();
277 0 ▶ return unless ref $item;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $item 0 0 0
278 0 return $item;
279 0 };
280 0 };
281 }
282
283 0 ▶sub take_until {
Subroutine take_until: not called CC=1 SCAR=6.9
Pod undocumented
284 0 my ($self, $predicate) = @_;
285 0 ▶ return $self->take_while(sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
286 0 !$predicate->($_);
287 0 });
288 }
289
290 0 ▶sub take_while {
Subroutine take_while: not called CC=1 SCAR=6.9
Pod undocumented
291 0 my ($self, $predicate) = @_;
292 0 ▶ return _create sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
293 0 ▶ return sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
294 0 state $base = $self->new();
295 0 my $item = $base->();
296 0 ▶ return unless ref $item;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $item 0 0 0
297 0 local $_ = $$item;
298 0 ▶ return unless $predicate->($_);
Branch: 1 branch
BranchTrueFalseTotal
unless &$predicate($_) 0 0 0
299 0 return $item;
300 0 };
301 0 };
302 }
303
304 0 ▶sub group_by {
Subroutine group_by: not called CC=1 SCAR=6.9
Pod undocumented
305 0 my ($self, $key_extractor) = @_;
306 0 ▶ return _create sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
307 0 my $base = $self->new;
308 0 my %temp;
309 0 while (1) {
310 0 my $item = $base->();
311 0 ▶ last unless ref $item;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $item 0 0 0
312 0 local $_ = $$item;
313 0 my $key = $key_extractor->($_);
314 0 push @{ $temp{$key} }, $_;
315 }
316
317 my @temp = map {
318 0 Acme::IEnumerable::Grouping->from_list($_, @{$temp{$_}})
319 } keys %temp;
320
321 0 return Acme::IEnumerable->from_list(@temp)->new;
322 0 };
323 }
324
325 0 ▶sub stack_by {
Subroutine stack_by: not called CC=1 SCAR=6.9
Pod undocumented
326 0 my ($self, $key_extractor) = @_;
327 0 ▶ return _create sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
328 # TODO: make this more lazy?
329 0 my $base = $self->new;
330 0 my @list;
331 0 while (1) {
332 0 my $item = $base->();
333 0 ▶ last unless ref $item;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $item 0 0 0
334 0 local $_ = $$item;
335 0 my $key = $key_extractor->($_);
336 0 ▶ if (not @list or $key ne $list[-1]->{key}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not @list or $key ne $list[-1]{"key"}) 0 0 0
Condition0%0/3
not @list or $key ne $list[-1]{"key"}
l!l&&r!l&&!r
000
MC/DC0%0/2
not @list or $key ne $list[-1]{"key"}
not @list $key ne $list[-1]{"key"}
Truth table0%0/3
not(A) or B
A= not @listB= $key ne $list[-1]{"key"}
ABresult
1X1
011
000
337 0 push @list, {
338 key => $key,
339 };
340 }
341 0 push @{ $list[-1]->{value} }, $_;
342 }
343
344 my @temp = map {
345 0 Acme::IEnumerable::Grouping->from_list($_->{key}, @{ $_->{value} })
346 } @list;
347
348 0 return Acme::IEnumerable->from_list(@temp)->new;
349 0 };
350 }
351
352 0 ▶sub skip {
Subroutine skip: not called CC=1 SCAR=6.9
Pod undocumented
353 0 my ($self, $count) = @_;
354 0 ▶ return _create sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
355 0 ▶ return sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
356 0 state $base = $self->new();
357 0 state $left = $count;
358 0 ▶ while ($left) {
Branch: 1 branch
BranchTrueFalseTotal
if ($left) 0 0 0
359 0 my $item = $base->();
360 0 ▶ return unless ref $item;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $item 0 0 0
361 0 $left--;
362 }
363 0 return $base->();
364 0 };
365 0 };
366 }
367
368 0 ▶sub skip_while {
Subroutine skip_while: not called CC=1 SCAR=6.9
Pod undocumented
369 0 my ($self, $predicate) = @_;
370 0 ▶ return _create sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
371 0 ▶ return sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
372 0 state $base = $self->new();
373 0 state $skip = 1;
374 0 ▶ while ($skip) {
Branch: 1 branch
BranchTrueFalseTotal
if ($skip) 0 0 0
375 0 my $item = $base->();
376 0 ▶ return unless ref $item;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $item 0 0 0
377 0 local $_ = $$item;
378 0 $skip &= !! $predicate->($_);
379 0 ▶ return $item unless $skip;
Branch: 1 branch
BranchTrueFalseTotal
unless $skip 0 0 0
380 }
381 0 return $base->();
382 0 };
383 }
384 0 }
385
386 0 ▶sub element_at {
Subroutine element_at: not called CC=4 SCAR=26.4
Pod undocumented
387 0 my ($self, $index) = @_;
388
389 0 ▶ Carp::cluck "Index out of range for element_at" if $index < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $index < 0 0 0 0
390
391 0 my $base = $self->new();
392 0 while (1) {
393 0 my $item = $base->();
394 0 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $item) 0 0 0
395 4 ▶ use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
396 0 ▶ warn Dumper[$self->count(sub { warn Data::Dumper::Dumper($_); 1; })];
Subroutine __ANON__: not called CC=1 SCAR=6.9
397 0 Carp::cluck "Index out of range for element_at";
398 } unless ref $item;
399 0 ▶ return $$item unless $index--;
Branch: 1 branch
BranchTrueFalseTotal
unless $index-- 0 0 0
400 }
401 0 Carp::confess("Impossible");
402 }
403
404 0 ▶sub last {
Subroutine last: not called CC=4 SCAR=30.0
Pod undocumented
405 0 my ($self) = @_;
406 0 my $base = $self->new();
407 0 my $last;
408 0 while (1) {
409 0 my $item = $base->();
410 0 ▶ croak unless ref $item or ref $last;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $item or ref $last 0 0 0
Condition0%0/3
ref $item or ref $last
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $item or ref $last
ref $item ref $last
Truth table0%0/3
A or B
A= ref $itemB= ref $last
ABresult
1X1
011
000
411 0 ▶ return $$last unless ref $item;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $item 0 0 0
412 0 $last = $item;
413 }
414 0 Carp::confess("Impossible");
415 }
416
417 0 ▶sub first {
Subroutine first: not called CC=1 SCAR=6.9
Pod undocumented
418 0 $_[0]->element_at(0);
419 }
420
421 0 ▶sub first_or_default {
Subroutine first_or_default: not called CC=2 SCAR=17.9
Pod undocumented
422 0 my ($self, $default) = @_;
423 0 my $base = $self->new();
424 0 my $item = $base->();
425 0 ▶ return $default unless ref $item;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $item 0 0 0
426 0 return $$item;
427 }
428
429 0 ▶sub last_or_default {
Subroutine last_or_default: not called CC=3 SCAR=24.8
Pod undocumented
430 0 my ($self, $default) = @_;
431 0 my $base = $self->new();
432 0 my $item = $base->();
433 0 ▶ return $default unless ref $item;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $item 0 0 0
434 0 while (1) {
435 0 my $next = $base->();
436 0 ▶ return $$item unless ref $next;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $next 0 0 0
437 0 $item = $next;
438 }
439 }
440
441 0 ▶sub count {
Subroutine count: not called CC=3 SCAR=24.8
Pod undocumented
442 0 my ($self, $predicate) = @_;
443 0 ▶ $predicate //= sub { 1 };
Subroutine __ANON__: not called CC=1 SCAR=6.9
Condition0%0/3
$predicate //= sub { 1; }
l!l&&r!l&&!r
000
MC/DC0%0/2
$predicate //= sub { 1; }
$predicate sub { 1; }
Truth table0%0/3
A //= B
A= $predicateB= sub { 1; }
ABresult
1X1
011
000
444 0 my $base = $self->new();
445 0 while (1) {
446 0 my $counter = 0;
447 0 my $item = $base->();
448 0 ▶ return $counter unless ref $item;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $item 0 0 0
449 0 local $_ = $$item;
450 0 $counter += 0 + !! $predicate->($_);
451 }
452 0 Carp::confess("Impossible");
453 }
454
455 0 ▶sub select {
Subroutine select: not called CC=1 SCAR=6.9
Pod undocumented
456 0 my ($self, $projection) = @_;
457 0 ▶ return _create sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
458 0 ▶ return sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
459 0 state $base = $self->new();
460 0 my $item = $base->();
461 0 ▶ return unless ref $item;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $item 0 0 0
462 0 local $_ = $$item;
463 0 return \($projection->($_));
464 0 };
465 0 };
466 }
467
468 0 ▶sub where {
Subroutine where: not called CC=1 SCAR=6.9
Pod undocumented
469 0 my ($self, $predicate) = @_;
470 0 ▶ return _create sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
471 0 ▶ return sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
472 0 state $base = $self->new();
473 0 while (1) {
474 0 my $item = $base->();
475 0 ▶ return unless ref $item;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $item 0 0 0
476 0 local $_ = $$item;
477 0 ▶ next unless $predicate->($_);
Branch: 1 branch
BranchTrueFalseTotal
unless &$predicate($_) 0 0 0
478 0 return $item;
479 }
480 0 };
481 0 };
482 }
483
484 0 ▶sub zip {
Subroutine zip: not called CC=1 SCAR=6.9
Pod undocumented
485 0 my ($self, $other) = @_;
486 0 ▶ return _create sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
487 0 ▶ return sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
488 0 state $base1 = $self->new();
489 0 state $base2 = $other->new();
490 0 while (1) {
491 0 my $item1 = $base1->();
492 0 ▶ return unless ref $item1;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $item1 0 0 0
493 0 my $item2 = $base2->();
494 0 ▶ return unless ref $item2;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $item2 0 0 0
495 0 return \[$$item1, $$item2]
496 }
497 0 };
498 0 };
499 }
500
501 0 ▶sub pairwise {
Subroutine pairwise: not called CC=3 SCAR=24.8
Pod undocumented
502 # TODO: make variant with a seed?
503 0 my ($self, $func) = @_;
504 0 return $self->each_cons(2, $func);
505
506 # ...
507 0 my $base = $self->new();
508 0 my $prev = $base->();
509 0 ▶ return unless ref $prev;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $prev 0 0 0
510 0 while (1) {
511 0 my $curr = $base->();
512 0 ▶ return unless ref $curr;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $curr 0 0 0
513 0 $func->($$prev, $$curr);
514 0 $prev = $curr;
515 }
516 0 Carp::confess("Impossible");
517 }
518
519 0 ▶sub each_cons {
Subroutine each_cons: not called CC=4 SCAR=30.0
Pod undocumented
520 0 my ($self, $count, $func) = @_;
521 0 my $base = $self->new();
522 0 my @prev;
523 0 ▶ while ($count-- > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($count-- > 1) 0 0 0
524 0 my $prev = $base->();
525 0 ▶ return unless ref $prev;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $prev 0 0 0
526 0 push @prev, $$prev;
527 }
528 0 while (1) {
529 0 my $curr = $base->();
530 0 ▶ return unless ref $curr;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $curr 0 0 0
531 0 $func->(@prev, $$curr);
532 0 push @prev, $$curr;
533 0 shift @prev;
534 }
535 0 Carp::confess("Impossible");
536 }
537
538
539 0 ▶sub aggregate {
Subroutine aggregate: not called CC=5 SCAR=34.0
Pod undocumented
540 0 my $self = shift;
541 0 my $base = $self->new();
542 0 my ($func, $seed);
543
544 0 ▶ if (@_ == 1) {
Branch: 2 branches
BranchTrueFalseTotal
if (@_ == 1) { } 0 0 0
elsif (@_ == 2) { } 0 0 0
545 0 $func = shift;
546 0 my $item = $base->();
547 0 ▶ croak unless ref $item;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $item 0 0 0
548 0 $seed = $$item;
549 } elsif (@_ == 2) {
550 0 $seed = shift;
551 0 $func = shift;
552 } else {
553 # ...
554 }
555
556 0 while (1) {
557 0 my $item = $base->();
558 0 ▶ return $seed unless ref $item;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $item 0 0 0
559 0 $seed = $func->($seed, $$item);
560 }
561 0 Carp::confess("Impossible");
562 }
563
564 0 ▶sub average {
Subroutine average: not called CC=3 SCAR=24.8
Pod undocumented
565 0 my ($self) = @_;
566 0 my $base = $self->new();
567
568 0 my $item = $base->();
569 0 ▶ return unless ref $item;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $item 0 0 0
570
571 0 my $count = 0;
572 0 my $total = 0;
573
574 0 while (1) {
575 0 $total += $$item;
576 0 $count += 1;
577 0 $item = $base->();
578 0 ▶ return $total/$count unless ref $item;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $item 0 0 0
579 }
580 }
581
582 0 ▶sub min {
Subroutine min: not called CC=1 SCAR=6.9
Pod undocumented
583 0 my ($self) = @_;
584 0 ▶ return $self->aggregate(sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
585 0 ▶ $_[0] < $_[1] ? $_[0] : $_[1]
Branch: 1 branch
BranchTrueFalseTotal
$_[0] < $_[1] ? : 0 0 0
586 0 });
587 }
588
589 0 ▶sub max {
Subroutine max: not called CC=1 SCAR=6.9
Pod undocumented
590 0 my ($self) = @_;
591 0 ▶ return $self->aggregate(sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
592 0 ▶ $_[0] > $_[1] ? $_[0] : $_[1]
Branch: 1 branch
BranchTrueFalseTotal
$_[0] > $_[1] ? : 0 0 0
593 0 });
594 }
595
596 0 ▶sub all {
Subroutine all: not called CC=3 SCAR=24.8
Pod undocumented
597 0 my ($self, $predicate) = @_;
598 0 my $base = $self->new();
599 0 while (1) {
600 0 my $item = $base->();
601 0 ▶ return 1 unless ref $item;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $item 0 0 0
602 0 local $_ = $$item;
603 0 ▶ return 0 unless $predicate->($_);
Branch: 1 branch
BranchTrueFalseTotal
unless &$predicate($_) 0 0 0
604 }
605 0 Carp::confess("Impossible");
606 }
607
608 0 ▶sub allplus {
Subroutine allplus: not called CC=3 SCAR=24.8
Pod undocumented
609 0 my ($self, $predicate) = @_;
610 0 my $base = $self->new();
611 0 my $okay = 0;
612 0 while (1) {
613 0 my $item = $base->();
614 0 ▶ return $okay unless ref $item;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $item 0 0 0
615 0 local $_ = $$item;
616 0 $okay = $predicate->($_);
617 0 ▶ return 0 unless $okay;
Branch: 1 branch
BranchTrueFalseTotal
unless $okay 0 0 0
618 }
619 0 Carp::confess("Impossible");
620 }
621
622 0 ▶sub any {
Subroutine any: not called CC=4 SCAR=30.0
Pod undocumented
623 0 my ($self, $predicate) = @_;
624 0 ▶ $predicate //= sub { 1 };
Subroutine __ANON__: not called CC=1 SCAR=6.9
Condition0%0/3
$predicate //= sub { 1; }
l!l&&r!l&&!r
000
MC/DC0%0/2
$predicate //= sub { 1; }
$predicate sub { 1; }
Truth table0%0/3
A //= B
A= $predicateB= sub { 1; }
ABresult
1X1
011
000
625 0 my $base = $self->new();
626 0 while (1) {
627 0 my $item = $base->();
628 0 ▶ return 0 unless ref $item;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $item 0 0 0
629 0 local $_ = $$item;
630 0 ▶ return 1 if $predicate->($_);
Branch: 1 branch
BranchTrueFalseTotal
if &$predicate($_) 0 0 0
631 }
632 0 Carp::confess("Impossible");
633 }
634
635 0 ▶sub reverse {
Subroutine reverse: not called CC=1 SCAR=6.9
Pod undocumented
636 0 my $self = shift;
637 0 Acme::IEnumerable->from_list(reverse $self->to_perl);
638 }
639
640 0 ▶sub sum {
Subroutine sum: not called CC=1 SCAR=6.9
Pod undocumented
641 0 my $self = shift;
642 0 ▶ return $self->aggregate(0, sub { $_[0] + $_[1] });
Subroutine __ANON__: not called CC=1 SCAR=6.9
643 }
644
645 3 ▶sub to_perl {
Subroutine to_perl: called CC=2 SCAR=6.9
Pod undocumented
646 3 my $self = shift;
647 3 my @result;
648 3 my $enum = $self->new();
649 3 ▶ for (my $item = $enum->(); ref $item; $item = $enum->()) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $item) 9 3 12
650 9 push @result, $$item;
651 }
652 3 @result;
653 }
654
655 0 ▶sub to_list {
Subroutine to_list: not called CC=1 SCAR=6.9
Pod undocumented
656 0 my ($self) = @_;
657 0 Acme::IEnumerable->from_list($self->to_perl);
658 }
659
660 0 ▶sub for_each {
Subroutine for_each: not called CC=2 SCAR=17.9
Pod undocumented
661 0 my ($self, $action) = @_;
662 0 my $enum = $self->new();
663 0 ▶ for (my $item = $enum->(); ref $item; $item = $enum->()) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $item) 0 0 0
664 0 local $_ = $$item;
665 0 $action->($_);
666 }
667 }
668
669 #####################################################################
670 #
671 #####################################################################
672 # sub select_many { ... }
673 # sub contains { ... }
674 # sub sequence_equal { ... }
675 # sub distinct { ... }
676 # sub union { ... }
677 # sub except { ... }
678 # sub intersect { ... }
679 # sub default_if_empty { ... }
680 # sub single_or_default { ... }
681 # sub concat { ... }
682 # sub group_join { ... }
683 # sub join { ... }
684 # sub empty { ... }
685 # sub cast { ... }
686 # sub to_lookup { ...}
687 # sub to_dictionary { ... }
688
689 #####################################################################
690 #
691 #####################################################################
692 # sub distinct_by { ... }
693 # sub min_by { ... }
694 # sub max_by { ... }
695
696 # sub to_enumerable { ... }
697
698
699 4 1;
700
701 __END__
↑ Summary