blib/lib/Venus/Array.pm

filter: Statementstmt 98.3% 295 / 300 Branchbran 80.6% 108 / 134 Conditioncond 57.1% 8 / 14 MC/DCmcdc 33.3% 3 / 9 Subroutinesub 88.3% 53 / 60 Podpod 100% 47 / 47 totaltotal 91.1% 514 / 564 CC 74 SCAR 14.3
CC
74
Cov
92%
sets
9.5
puts
9.2
none
6.2
CRAP 4.2
« blib/lib/Venus/Random.pm ↑ Summary blib/lib/Venus/Yaml.pm »
1 package Venus::Array;
2  
3 28 ▶use 5.018;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 28 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 28 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 # IMPORTS
9  
10 28 ▶use Venus::Class 'base', 'with';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 # INHERITS
13  
14 28 base 'Venus::Kind::Value';
15  
16 # INTEGRATES
17  
18 28 with 'Venus::Role::Mappable';
19  
20 # METHODS
21  
22 7 ▶sub all {
Subroutine all: called CC=6 SCAR=17.9
Pod documented
23 7 my ($self, $code) = @_;
24  
25 7 my $data = $self->get;
26  
27 7 ▶ $code = sub{} if !$code;
Subroutine __ANON__: not called CC=1 SCAR=0.4
Branch: 1 branch
BranchTrueFalseTotal
unless $code 0 7 7
28  
29 7 my $failed = 0;
30  
31 7 ▶ for (my $i = 0; $i < @$data; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$data) 30 5 35
32 30 my $index = $i;
33 30 my $value = $data->[$i];
34  
35 30 local $_ = $value;
36 30 ▶ $failed++ if !$code->($index, $value);
Branch: 1 branch
BranchTrueFalseTotal
unless &$code($index, $value) 2 28 30
37  
38 30 ▶ CORE::last if $failed;
Branch: 1 branch
BranchTrueFalseTotal
if $failed 2 28 30
39 }
40  
41 7 ▶ return $failed ? false : true;
Branch: 1 branch
BranchTrueFalseTotal
$failed ? : 2 5 7
42 }
43  
44 11 ▶sub any {
Subroutine any: called CC=6 SCAR=17.9
Pod documented
45 11 my ($self, $code) = @_;
46  
47 11 my $data = $self->get;
48  
49 11 ▶ $code = sub{} if !$code;
Subroutine __ANON__: not called CC=1 SCAR=0.4
Branch: 1 branch
BranchTrueFalseTotal
unless $code 0 11 11
50  
51 11 my $found = 0;
52  
53 11 ▶ for (my $i = 0; $i < @$data; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$data) 33 3 36
54 33 my $index = $i;
55 33 my $value = $data->[$i];
56  
57 33 local $_ = $value;
58 33 ▶ $found++ if $code->($index, $value);
Branch: 1 branch
BranchTrueFalseTotal
if &$code($index, $value) 8 25 33
59  
60 33 ▶ CORE::last if $found;
Branch: 1 branch
BranchTrueFalseTotal
if $found 8 25 33
61 }
62  
63 11 ▶ return $found ? true : false;
Branch: 1 branch
BranchTrueFalseTotal
$found ? : 8 3 11
64 }
65  
66 2 ▶sub call {
Subroutine call: called CC=1 SCAR=0.0
Pod documented
67 2 my ($self, $mapper, $method, @args) = @_;
68  
69 2 require Venus::What;
70  
71 18 ▶ return $self->$mapper(sub{
Subroutine __ANON__: called CC=1 SCAR=0.0
72 18 my ($key, $val) = @_;
73  
74 18 my $what = Venus::What->new($val)->deduce;
75  
76 18 local $_ = $what;
77  
78 18 $what->$method(@args)
79 2 });
80 }
81  
82 7 ▶sub count {
Subroutine count: called CC=1 SCAR=0.0
Pod documented
83 7 my ($self) = @_;
84  
85 7 my $data = $self->get;
86  
87 7 return scalar(@$data);
88 }
89  
90 183 ▶sub default {
Subroutine default: called CC=1 SCAR=0.0
Pod documented
91 183 return [];
92 }
93  
94 1 ▶sub delete {
Subroutine delete: called CC=1 SCAR=0.0
Pod documented
95 1 my ($self, $index) = @_;
96  
97 1 my $data = $self->get;
98  
99 1 return CORE::delete($data->[$index]);
100 }
101  
102 14 ▶sub each {
Subroutine each: called CC=4 SCAR=13.9
Pod documented
103 14 my ($self, $code) = @_;
104  
105 14 my $data = $self->get;
106  
107 14 ▶ $code = sub{} if !$code;
Subroutine __ANON__: not called CC=1 SCAR=0.4
Branch: 1 branch
BranchTrueFalseTotal
unless $code 0 14 14
108  
109 14 my $result = [];
110  
111 14 ▶ for (my $i = 0; $i < @$data; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$data) 48 14 62
112 48 my $index = $i;
113 48 my $value = $data->[$i];
114  
115 48 local $_ = $value;
116 48 CORE::push(@$result, $code->($index, $value));
117 }
118  
119 14 ▶ return wantarray ? (@$result) : $result;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 12 2 14
120 }
121  
122 1 ▶sub empty {
Subroutine empty: called CC=1 SCAR=0.0
Pod documented
123 1 my ($self) = @_;
124  
125 1 my $data = $self->get;
126  
127 1 $#$data = -1;
128  
129 1 return $self;
130 }
131  
132 1 ▶sub exists {
Subroutine exists: called CC=2 SCAR=7.0
Pod documented
133 1 my ($self, $index) = @_;
134  
135 1 my $data = $self->get;
136  
137 1 ▶ return $index <= $#{$data} ? true : false;
Branch: 1 branch
BranchTrueFalseTotal
$index <= $#{$data;} ? : 1 0 1
138 }
139  
140 73 ▶sub find {
Subroutine find: called CC=6 SCAR=18.1
Pod documented
141 73 my ($self, @args) = @_;
142  
143 73 my $seen = 0;
144 73 my $item = my $data = $self->get;
145  
146 73 ▶ for (my $i = 0; $i < @args; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @args) 103 73 176
147 103 ▶ if (ref($item) eq 'ARRAY') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $item eq 'ARRAY') { } 74 29 103
elsif (ref $item eq 'HASH') { } 25 4 29
148 74 ▶ if ($args[$i] !~ /^\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($args[$i] =~ /^\d+$/u) 0 74 74
149 0 $item = undef;
150 0 $seen = 0;
151 0 CORE::last;
152 }
153 74 $seen = $args[$i] <= $#{$item};
154 74 $item = $item->[$args[$i]];
155 }
156 elsif (ref($item) eq 'HASH') {
157 25 $seen = exists $item->{$args[$i]};
158 25 $item = $item->{$args[$i]};
159 }
160 else {
161 4 $item = undef;
162 4 $seen = 0;
163 }
164 }
165  
166 73 ▶ return wantarray ? ($item, int(!!$seen)) : $item;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 27 46 73
167 }
168  
169 1 ▶sub first {
Subroutine first: called CC=1 SCAR=0.0
Pod documented
170 1 my ($self) = @_;
171  
172 1 return $self->get->[0];
173 }
174  
175 455 ▶sub get {
Subroutine get: called CC=2 SCAR=6.9
Pod documented
176 455 my ($self, @args) = @_;
177  
178 455 ▶ return $self->value if !@args;
Branch: 1 branch
BranchTrueFalseTotal
unless @args 451 4 455
179  
180 4 my ($index) = @args;
181  
182 4 return $self->value->[$index];
183 }
184  
185 5 ▶sub gets {
Subroutine gets: called CC=2 SCAR=6.9
Pod documented
186 5 my ($self, @args) = @_;
187  
188 5 my $result = $self->puts(map +(undef, $_), @args);
189  
190 5 ▶ return wantarray ? (@{$result}) : $result;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 4 5
191 }
192  
193 3 ▶sub grep {
Subroutine grep: called CC=5 SCAR=16.2
Pod documented
194 3 my ($self, $code) = @_;
195  
196 3 my $data = $self->get;
197  
198 3 ▶ $code = sub{} if !$code;
Subroutine __ANON__: not called CC=1 SCAR=0.4
Branch: 1 branch
BranchTrueFalseTotal
unless $code 0 3 3
199  
200 3 my $result = [];
201  
202 3 ▶ for (my $i = 0; $i < @$data; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$data) 27 3 30
203 27 my $index = $i;
204 27 my $value = $data->[$i];
205  
206 27 local $_ = $value;
207 27 ▶ CORE::push(@$result, $value) if $code->($index, $value);
Branch: 1 branch
BranchTrueFalseTotal
if &$code($index, $value) 17 10 27
208 }
209  
210 3 ▶ return wantarray ? (@$result) : $result;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 3 3
211 }
212  
213 5 ▶sub head {
Subroutine head: called CC=3 SCAR=11.0
Pod documented
214 5 my ($self, $size) = @_;
215  
216 5 my $data = $self->get;
217  
218 5 ▶ $size = !$size ? 1 : $size > @$data ? @$data : $size;
Branch: 2 branches
BranchTrueFalseTotal
!$size ? : 1 4 5
$size > @$data ? : 1 3 4
219  
220 5 my $index = $size - 1;
221  
222 5 return [@{$data}[0..$index]];
223 }
224  
225 2 ▶sub iterator {
Subroutine iterator: called CC=1 SCAR=0.0
Pod documented
226 2 my ($self) = @_;
227  
228 2 my $data = $self->get;
229  
230 2 my $i = 0;
231 2 my $j = 0;
232  
233 20 ▶ return sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
234 20 ▶ return undef if $i > $#{$data};
Branch: 1 branch
BranchTrueFalseTotal
if $i > $#{$data;} 2 18 20
235 18 ▶ return wantarray ? ($j++, $data->[$i++]) : $data->[$i++];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 9 9 18
236 }
237 2 }
238  
239 2 ▶sub join {
Subroutine join: called CC=2 SCAR=6.9
Pod documented
240 2 my ($self, $delimiter) = @_;
241  
242 2 my $data = $self->get;
243  
244 2 ▶ return CORE::join($delimiter // '', @$data);
Condition100%2/2
$delimiter // ""
l!l
11
MC/DC100%1/1
$delimiter // ""
$delimiter
Truth table100%2/2
A
A= $delimiter
Aresult
11
00
245 }
246  
247 2 ▶sub keyed {
Subroutine keyed: called CC=1 SCAR=0.0
Pod documented
248 2 my ($self, @keys) = @_;
249  
250 2 my $data = $self->get;
251  
252 2 my $i = 0;
253 2 return {map { $_ => $data->[$i++] } @keys};
254 }
255  
256 1 ▶sub keys {
Subroutine keys: called CC=1 SCAR=0.0
Pod documented
257 1 my ($self) = @_;
258  
259 1 my $data = $self->get;
260  
261 1 return [0..$#{$data}];
262 }
263  
264 1 ▶sub last {
Subroutine last: called CC=1 SCAR=0.0
Pod documented
265 1 my ($self) = @_;
266  
267 1 return $self->value->[-1];
268 }
269  
270 1 ▶sub length {
Subroutine length: called CC=1 SCAR=0.0
Pod documented
271 1 my ($self) = @_;
272  
273 1 return $self->count;
274 }
275  
276 4 ▶sub list {
Subroutine list: called CC=2 SCAR=6.9
Pod documented
277 4 my ($self) = @_;
278  
279 4 ▶ return wantarray ? (@{$self->value}) : scalar(@{$self->value});
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 3 1 4
280 }
281  
282 3 ▶sub map {
Subroutine map: called CC=4 SCAR=13.9
Pod documented
283 3 my ($self, $code) = @_;
284  
285 3 my $data = $self->get;
286  
287 3 ▶ $code = sub{} if !$code;
Subroutine __ANON__: not called CC=1 SCAR=0.4
Branch: 1 branch
BranchTrueFalseTotal
unless $code 0 3 3
288  
289 3 my $result = [];
290  
291 3 ▶ for (my $i = 0; $i < @$data; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$data) 27 3 30
292 27 my $index = $i;
293 27 my $value = $data->[$i];
294  
295 27 local $_ = $value;
296 27 CORE::push(@$result, $code->($index, $value));
297 }
298  
299 3 ▶ return wantarray ? (@$result) : $result;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 3 3
300 }
301  
302 2 ▶sub merge {
Subroutine merge: called CC=1 SCAR=0.0
Pod documented
303 2 my ($self, @rvalues) = @_;
304  
305 2 require Venus;
306  
307 2 my $lvalue = [@{$self->get}];
308  
309 2 return Venus::merge_swap($lvalue, @rvalues);
310 }
311  
312 2 ▶sub none {
Subroutine none: called CC=6 SCAR=18.3
Pod documented
313 2 my ($self, $code) = @_;
314  
315 2 my $data = $self->get;
316  
317 2 ▶ $code = sub{} if !$code;
Subroutine __ANON__: not called CC=1 SCAR=0.4
Branch: 1 branch
BranchTrueFalseTotal
unless $code 0 2 2
318  
319 2 my $found = 0;
320  
321 2 ▶ for (my $i = 0; $i < @$data; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$data) 18 2 20
322 18 my $index = $i;
323 18 my $value = $data->[$i];
324  
325 18 local $_ = $value;
326 18 ▶ $found++ if $code->($index, $value);
Branch: 1 branch
BranchTrueFalseTotal
if &$code($index, $value) 0 18 18
327  
328 18 ▶ CORE::last if $found;
Branch: 1 branch
BranchTrueFalseTotal
if $found 0 18 18
329 }
330  
331 2 ▶ return $found ? false : true;
Branch: 1 branch
BranchTrueFalseTotal
$found ? : 0 2 2
332 }
333  
334 2 ▶sub one {
Subroutine one: called CC=6 SCAR=18.1
Pod documented
335 2 my ($self, $code) = @_;
336  
337 2 my $data = $self->get;
338  
339 2 ▶ $code = sub{} if !$code;
Subroutine __ANON__: not called CC=1 SCAR=0.4
Branch: 1 branch
BranchTrueFalseTotal
unless $code 0 2 2
340  
341 2 my $found = 0;
342  
343 2 ▶ for (my $i = 0; $i < @$data; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$data) 18 2 20
344 18 my $index = $i;
345 18 my $value = $data->[$i];
346  
347 18 local $_ = $value;
348 18 ▶ $found++ if $code->($index, $value);
Branch: 1 branch
BranchTrueFalseTotal
if &$code($index, $value) 2 16 18
349  
350 18 ▶ CORE::last if $found > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $found > 1 0 18 18
351 }
352  
353 2 ▶ return $found == 1 ? true : false;
Branch: 1 branch
BranchTrueFalseTotal
$found == 1 ? : 2 0 2
354 }
355  
356 3 ▶sub order {
Subroutine order: called CC=1 SCAR=0.0
Pod documented
357 3 my ($self, @args) = @_;
358  
359 3 my $data = $self->get;
360  
361 3 my %seen = ();
362  
363 3 @{$data} = (map $data->[$_], grep !$seen{$_}++, (@args), 0..$#{$data});
364  
365 3 return $self;
366 }
367  
368 5 ▶sub pairs {
Subroutine pairs: called CC=2 SCAR=7.0
Pod documented
369 5 my ($self) = @_;
370  
371 5 my $data = $self->get;
372  
373 5 my $i = 0;
374 5 my $result = [map +[$i++, $_], @$data];
375  
376 5 ▶ return wantarray ? (@$result) : $result;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 5 5
377 }
378  
379 70 ▶sub path {
Subroutine path: called CC=2 SCAR=6.9
Pod documented
380 70 my ($self, $path) = @_;
381  
382 70 my @path = CORE::grep(/./, CORE::split(/\W/, $path));
383  
384 70 ▶ return wantarray ? ($self->find(@path)) : $self->find(@path);
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 27 43 70
385 }
386  
387 2 ▶sub part {
Subroutine part: called CC=4 SCAR=13.9
Pod documented
388 2 my ($self, $code) = @_;
389  
390 2 my $data = $self->get;
391  
392 2 my $results = [[], []];
393  
394 2 ▶ for (my $i = 0; $i < @$data; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$data) 18 2 20
395 18 my $index = $i;
396 18 my $value = $data->[$i];
397 18 local $_ = $value;
398 18 my $result = $code->($index, $value);
399 18 ▶ my $slot = $result ? $$results[0] : $$results[1];
Branch: 1 branch
BranchTrueFalseTotal
$result ? : 8 10 18
400  
401 18 CORE::push(@$slot, $value);
402 }
403  
404 2 ▶ return wantarray ? (@$results) : $results;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 2 2
405 }
406  
407 1 ▶sub pop {
Subroutine pop: called CC=1 SCAR=0.0
Pod documented
408 1 my ($self) = @_;
409  
410 1 my $data = $self->get;
411  
412 1 return CORE::pop(@$data);
413 }
414  
415 2 ▶sub push {
Subroutine push: called CC=1 SCAR=0.0
Pod documented
416 2 my ($self, @args) = @_;
417  
418 2 my $data = $self->get;
419  
420 2 CORE::push(@$data, @args);
421  
422 2 return $data;
423 }
424  
425 10 ▶sub puts {
Subroutine puts: called CC=9 SCAR=22.2
Pod documented
426 10 my ($self, @args) = @_;
427  
428 10 my $result = [];
429  
430 10 ▶ for (my $i = 0; $i < @args; $i += 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @args) 24 10 34
431 24 my ($into, $path) = @args[$i, $i+1];
432  
433 24 ▶ next if !defined $path || $path eq '';
Branch: 1 branch
BranchTrueFalseTotal
if not defined $path or $path eq "" 0 24 24
Condition33%1/3
not defined $path or $path eq ""
l!l&&r!l&&!r
0024
MC/DC0%0/2
not defined $path or $path eq ""
not defined $path $path eq ""
Truth table33%1/3
not(A) or B
A= not defined $pathB= $path eq ""
ABresult
1X1
011
000
434  
435 24 my $value;
436 my @range;
437  
438 24 ▶ ($path, @range) = @{$path} if ref $path eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $path eq "ARRAY" 1 23 24
439  
440 24 $value = $self->path($path);
441  
442 24 ▶ if (ref $value eq 'ARRAY' && @range) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value eq "ARRAY" and @range) 1 23 24
Condition100%3/3
ref $value eq "ARRAY" and @range
!ll&&!rl&&r
1761
MC/DC100%2/2
ref $value eq "ARRAY" and @range
ref $value eq "ARRAY" @range
Truth table100%3/3
A and B
A= ref $value eq "ARRAY"B= @range
ABresult
0X0
100
111
443 1 $value = Venus::Array->new($value)->range(@range);
444 }
445  
446 24 ▶ if (ref $into eq 'SCALAR') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $into eq "SCALAR") 11 13 24
447 11 $$into = $value;
448 }
449  
450 24 CORE::push @{$result}, $value;
451 }
452  
453 0 ▶ return wantarray ? (@{$result}) : $result;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 10 10
454 }
455  
456 1 ▶sub random {
Subroutine random: called CC=1 SCAR=0.0
Pod documented
457 1 my ($self) = @_;
458  
459 1 my $data = $self->get;
460  
461 1 return @$data[rand($#{$data}+1)];
462 }
463  
464 100 ▶sub range {
Subroutine range: called CC=2 SCAR=6.9
Pod documented
465 100 my ($self, @args) = @_;
466  
467 100 ▶ return $self->slice(@args) if @args > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @args > 1 1 99 100
468  
469 99 require Venus::Range;
470  
471 99 return scalar Venus::Range->parse(@args, $self->get)->select;
472 }
473  
474 1 ▶sub reverse {
Subroutine reverse: called CC=1 SCAR=0.0
Pod documented
475 1 my ($self) = @_;
476  
477 1 my $data = $self->get;
478  
479 1 return [CORE::reverse(@$data)];
480 }
481  
482 1 ▶sub rotate {
Subroutine rotate: called CC=1 SCAR=0.0
Pod documented
483 1 my ($self) = @_;
484  
485 1 my $data = $self->get;
486  
487 1 CORE::push(@$data, CORE::shift(@$data));
488  
489 1 return $data;
490 }
491  
492 1 ▶sub rsort {
Subroutine rsort: called CC=1 SCAR=0.0
Pod documented
493 1 my ($self) = @_;
494  
495 1 my $data = $self->get;
496  
497 1 return [CORE::sort { $b cmp $a } @$data];
498 }
499  
500 13 ▶sub set {
Subroutine set: called CC=5 SCAR=17.8
Pod documented
501 13 my ($self, @args) = @_;
502  
503 13 ▶ return $self->value if !@args;
Branch: 1 branch
BranchTrueFalseTotal
unless @args 0 13 13
504  
505 13 ▶ return $self->value(@args) if @args == 1 && ref $args[0] eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if @args == 1 and ref $args[0] eq "ARRAY" 0 13 13
Condition33%1/3
@args == 1 and ref $args[0] eq "ARRAY"
!ll&&!rl&&r
1300
MC/DC0%0/2
@args == 1 and ref $args[0] eq "ARRAY"
@args == 1 ref $args[0] eq "ARRAY"
Truth table33%1/3
A and B
A= @args == 1B= ref $args[0] eq "ARRAY"
ABresult
0X0
100
111
506  
507 13 my ($index, $value) = @args;
508  
509 13 ▶ return if not defined $index;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $index 0 13 13
510  
511 13 return $self->value->[$index] = $value;
512 }
513  
514 13 ▶sub sets {
Subroutine sets: called CC=9 SCAR=22.5
Pod documented
515 13 my ($self, @args) = @_;
516  
517 13 my $result = [];
518  
519 13 ▶ for (my $i = 0; $i < @args; $i += 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @args) 29 13 42
520 29 my ($path, $data) = @args[$i, $i+1];
521  
522 29 CORE::push @{$result}, $data;
523  
524 29 ▶ next if !defined $path || $path eq "";
Branch: 1 branch
BranchTrueFalseTotal
if not defined $path or $path eq "" 0 29 29
Condition33%1/3
not defined $path or $path eq ""
l!l&&r!l&&!r
0029
MC/DC0%0/2
not defined $path or $path eq ""
not defined $path $path eq ""
Truth table33%1/3
not(A) or B
A= not defined $pathB= $path eq ""
ABresult
1X1
011
000
525  
526 29 ▶ if (my ($first, $last) = $path =~ /^(.*)\.(\w+)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = $path =~ /^(.*)\.(\w+)$/u) { } 16 13 29
527 16 ▶ my $value = $self->path($first) or next;
Branch: 1 branch
BranchTrueFalseTotal
my $value = $self->path($first) or next 16 0 16
528  
529 16 ▶ if (ref $value eq 'ARRAY') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $value eq 'ARRAY') { } 0 16 16
elsif (ref $value eq 'HASH') { } 14 2 16
530 0 $value->[$last] = $data;
531 }
532 elsif (ref $value eq 'HASH') {
533 14 $value->{$last} = $data;
534 }
535 }
536 else {
537 13 $self->set($path, $data);
538 }
539 }
540  
541 13 ▶ return wantarray ? (@{$result}) : $result;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 12 13
542 }
543  
544 1 ▶sub shift {
Subroutine shift: called CC=1 SCAR=0.0
Pod documented
545 1 my ($self) = @_;
546  
547 1 my $data = $self->get;
548  
549 1 return CORE::shift(@$data);
550 }
551  
552 1 ▶sub shuffle {
Subroutine shuffle: called CC=2 SCAR=6.9
Pod documented
553 1 my ($self) = @_;
554  
555 1 my $data = $self->get;
556 1 my $result = [@$data];
557  
558 1 for my $index (0..$#$result) {
559 9 my $other = int(rand(@$result));
560 9 my $stash = $result->[$index];
561 9 $result->[$index] = $result->[$other];
562 9 $result->[$other] = $stash;
563 }
564  
565 1 return $result;
566 }
567  
568 2 ▶sub slice {
Subroutine slice: called CC=1 SCAR=0.0
Pod documented
569 2 my ($self, @args) = @_;
570  
571 2 my $data = $self->get;
572  
573 2 return [@$data[@args]];
574 }
575  
576 1 ▶sub sort {
Subroutine sort: called CC=1 SCAR=0.0
Pod documented
577 1 my ($self) = @_;
578  
579 1 my $data = $self->get;
580  
581 1 return [CORE::sort { $a cmp $b } @$data];
582 }
583  
584 5 ▶sub tail {
Subroutine tail: called CC=3 SCAR=11.0
Pod documented
585 5 my ($self, $size) = @_;
586  
587 5 my $data = $self->get;
588  
589 5 ▶ $size = !$size ? 1 : $size > @$data ? @$data : $size;
Branch: 2 branches
BranchTrueFalseTotal
!$size ? : 1 4 5
$size > @$data ? : 1 3 4
590  
591 5 my $index = $#$data - ($size - 1);
592  
593 5 return [@{$data}[$index..$#$data]];
594 }
595  
596 1 ▶sub unique {
Subroutine unique: called CC=1 SCAR=0.0
Pod documented
597 1 my ($self) = @_;
598  
599 1 my $data = $self->get;
600  
601 1 my %seen;
602 1 return [CORE::grep { not $seen{$_}++ } @$data];
603 }
604  
605 1 ▶sub unshift {
Subroutine unshift: called CC=1 SCAR=0.0
Pod documented
606 1 my ($self, @args) = @_;
607  
608 1 my $data = $self->get;
609  
610 1 CORE::unshift(@$data, @args);
611  
612 1 return $data;
613 }
614  
615 28 1;
616  
617  
618  
619 =head1 NAME
620  
621 Venus::Array - Array Class
622  
623 =cut
624  
625 =head1 ABSTRACT
626  
627 Array Class for Perl 5
628  
629 =cut
630  
631 =head1 SYNOPSIS
632  
633 package main;
634  
635 use Venus::Array;
636  
637 my $array = Venus::Array->new([1..9]);
638  
639 # $array->random;
640  
641 =cut
642  
643 =head1 DESCRIPTION
644  
645 This package provides methods for manipulating array data.
646  
647 =cut
648  
649 =head1 INHERITS
650  
651 This package inherits behaviors from:
652  
653 L<Venus::Kind::Value>
654  
655 =cut
656  
657 =head1 INTEGRATES
658  
659 This package integrates behaviors from:
660  
661 L<Venus::Role::Mappable>
662  
663 =cut
664  
665 =head1 METHODS
666  
667 This package provides the following methods:
668  
669 =cut
670  
671 =head2 all
672  
673 all(coderef $code) (boolean)
674  
675 The all method returns true if the callback returns true for all of the
676 elements.
677  
678 I<Since C<0.01>>
679  
680 =over 4
681  
682 =item all example 1
683  
684 # given: synopsis;
685  
686 my $all = $array->all(sub {
687 $_ > 0;
688 });
689  
690 # 1
691  
692 =back
693  
694 =over 4
695  
696 =item all example 2
697  
698 # given: synopsis;
699  
700 my $all = $array->all(sub {
701 my ($key, $value) = @_;
702  
703 $value > 0;
704 });
705  
706 # 1
707  
708 =back
709  
710 =cut
711  
712 =head2 any
713  
714 any(coderef $code) (boolean)
715  
716 The any method returns true if the callback returns true for any of the
717 elements.
718  
719 I<Since C<0.01>>
720  
721 =over 4
722  
723 =item any example 1
724  
725 # given: synopsis;
726  
727 my $any = $array->any(sub {
728 $_ > 4;
729 });
730  
731 =back
732  
733 =over 4
734  
735 =item any example 2
736  
737 # given: synopsis;
738  
739 my $any = $array->any(sub {
740 my ($key, $value) = @_;
741  
742 $value > 4;
743 });
744  
745 =back
746  
747 =cut
748  
749 =head2 call
750  
751 call(string $iterable, string $method) (any)
752  
753 The call method executes the given method (named using the first argument)
754 which performs an iteration (i.e. takes a callback) and calls the method (named
755 using the second argument) on the object (or value) and returns the result of
756 the iterable method.
757  
758 I<Since C<1.02>>
759  
760 =over 4
761  
762 =item call example 1
763  
764 # given: synopsis
765  
766 package main;
767  
768 my $call = $array->call('map', 'incr');
769  
770 # [2..10]
771  
772 =back
773  
774 =over 4
775  
776 =item call example 2
777  
778 # given: synopsis
779  
780 package main;
781  
782 my $call = $array->call('grep', 'gt', 4);
783  
784 # [4..9]
785  
786 =back
787  
788 =cut
789  
790 =head2 cast
791  
792 cast(string $kind) (object | undef)
793  
794 The cast method converts L<"value"|Venus::Kind::Value> objects between
795 different I<"value"> object types, based on the name of the type provided. This
796 method will return C<undef> if the invocant is not a L<Venus::Kind::Value>.
797  
798 I<Since C<0.08>>
799  
800 =over 4
801  
802 =item cast example 1
803  
804 package main;
805  
806 use Venus::Array;
807  
808 my $array = Venus::Array->new;
809  
810 my $cast = $array->cast('array');
811  
812 # bless({ value => [] }, "Venus::Array")
813  
814 =back
815  
816 =over 4
817  
818 =item cast example 2
819  
820 package main;
821  
822 use Venus::Array;
823  
824 my $array = Venus::Array->new;
825  
826 my $cast = $array->cast('boolean');
827  
828 # bless({ value => 1 }, "Venus::Boolean")
829  
830 =back
831  
832 =over 4
833  
834 =item cast example 3
835  
836 package main;
837  
838 use Venus::Array;
839  
840 my $array = Venus::Array->new;
841  
842 my $cast = $array->cast('code');
843  
844 # bless({ value => sub { ... } }, "Venus::Code")
845  
846 =back
847  
848 =over 4
849  
850 =item cast example 4
851  
852 package main;
853  
854 use Venus::Array;
855  
856 my $array = Venus::Array->new;
857  
858 my $cast = $array->cast('float');
859  
860 # bless({ value => "1.0" }, "Venus::Float")
861  
862 =back
863  
864 =over 4
865  
866 =item cast example 5
867  
868 package main;
869  
870 use Venus::Array;
871  
872 my $array = Venus::Array->new;
873  
874 my $cast = $array->cast('hash');
875  
876 # bless({ value => {} }, "Venus::Hash")
877  
878 =back
879  
880 =over 4
881  
882 =item cast example 6
883  
884 package main;
885  
886 use Venus::Array;
887  
888 my $array = Venus::Array->new;
889  
890 my $cast = $array->cast('number');
891  
892 # bless({ value => 2 }, "Venus::Number")
893  
894 =back
895  
896 =over 4
897  
898 =item cast example 7
899  
900 package main;
901  
902 use Venus::Array;
903  
904 my $array = Venus::Array->new;
905  
906 my $cast = $array->cast('regexp');
907  
908 # bless({ value => qr/(?^u:\[\])/ }, "Venus::Regexp")
909  
910 =back
911  
912 =over 4
913  
914 =item cast example 8
915  
916 package main;
917  
918 use Venus::Array;
919  
920 my $array = Venus::Array->new;
921  
922 my $cast = $array->cast('scalar');
923  
924 # bless({ value => \[] }, "Venus::Scalar")
925  
926 =back
927  
928 =over 4
929  
930 =item cast example 9
931  
932 package main;
933  
934 use Venus::Array;
935  
936 my $array = Venus::Array->new;
937  
938 my $cast = $array->cast('string');
939  
940 # bless({ value => "[]" }, "Venus::String")
941  
942 =back
943  
944 =over 4
945  
946 =item cast example 10
947  
948 package main;
949  
950 use Venus::Array;
951  
952 my $array = Venus::Array->new;
953  
954 my $cast = $array->cast('undef');
955  
956 # bless({ value => undef }, "Venus::Undef")
957  
958 =back
959  
960 =cut
961  
962 =head2 count
963  
964 count() (number)
965  
966 The count method returns the number of elements within the array.
967  
968 I<Since C<0.01>>
969  
970 =over 4
971  
972 =item count example 1
973  
974 # given: synopsis;
975  
976 my $count = $array->count;
977  
978 # 9
979  
980 =back
981  
982 =cut
983  
984 =head2 default
985  
986 default() (arrayref)
987  
988 The default method returns the default value, i.e. C<[]>.
989  
990 I<Since C<0.01>>
991  
992 =over 4
993  
994 =item default example 1
995  
996 # given: synopsis;
997  
998 my $default = $array->default;
999  
1000 # []
1001  
1002 =back
1003  
1004 =cut
1005  
1006 =head2 delete
1007  
1008 delete(number $index) (any)
1009  
1010 The delete method returns the value of the element at the index specified after
1011 removing it from the array.
1012  
1013 I<Since C<0.01>>
1014  
1015 =over 4
1016  
1017 =item delete example 1
1018  
1019 # given: synopsis;
1020  
1021 my $delete = $array->delete(2);
1022  
1023 # 3
1024  
1025 =back
1026  
1027 =cut
1028  
1029 =head2 each
1030  
1031 each(coderef $code) (arrayref)
1032  
1033 The each method executes a callback for each element in the array passing the
1034 index and value as arguments. This method can return a list of values in
1035 list-context.
1036  
1037 I<Since C<0.01>>
1038  
1039 =over 4
1040  
1041 =item each example 1
1042  
1043 # given: synopsis;
1044  
1045 my $each = $array->each(sub {
1046 [$_]
1047 });
1048  
1049 # [[1], [2], [3], [4], [5], [6], [7], [8], [9]]
1050  
1051 =back
1052  
1053 =over 4
1054  
1055 =item each example 2
1056  
1057 # given: synopsis;
1058  
1059 my $each = $array->each(sub {
1060 my ($key, $value) = @_;
1061  
1062 [$key, $value]
1063 });
1064  
1065 # [
1066 # [0, 1],
1067 # [1, 2],
1068 # [2, 3],
1069 # [3, 4],
1070 # [4, 5],
1071 # [5, 6],
1072 # [6, 7],
1073 # [7, 8],
1074 # [8, 9],
1075 # ]
1076  
1077 =back
1078  
1079 =cut
1080  
1081 =head2 empty
1082  
1083 empty() (Venus::Array)
1084  
1085 The empty method drops all elements from the array.
1086  
1087 I<Since C<0.01>>
1088  
1089 =over 4
1090  
1091 =item empty example 1
1092  
1093 # given: synopsis;
1094  
1095 my $empty = $array->empty;
1096  
1097 # bless({ value => [] }, "Venus::Array")
1098  
1099 =back
1100  
1101 =cut
1102  
1103 =head2 eq
1104  
1105 eq(any $arg) (boolean)
1106  
1107 The eq method performs an I<"equals"> operation using the argument provided.
1108  
1109 I<Since C<0.08>>
1110  
1111 =over 4
1112  
1113 =item eq example 1
1114  
1115 package main;
1116  
1117 use Venus::Array;
1118  
1119 my $lvalue = Venus::Array->new;
1120 my $rvalue = Venus::Array->new;
1121  
1122 my $result = $lvalue->eq($rvalue);
1123  
1124 # 1
1125  
1126 =back
1127  
1128 =over 4
1129  
1130 =item eq example 2
1131  
1132 package main;
1133  
1134 use Venus::Array;
1135 use Venus::Code;
1136  
1137 my $lvalue = Venus::Array->new;
1138 my $rvalue = Venus::Code->new;
1139  
1140 my $result = $lvalue->eq($rvalue);
1141  
1142 # 0
1143  
1144 =back
1145  
1146 =over 4
1147  
1148 =item eq example 3
1149  
1150 package main;
1151  
1152 use Venus::Array;
1153 use Venus::Float;
1154  
1155 my $lvalue = Venus::Array->new;
1156 my $rvalue = Venus::Float->new;
1157  
1158 my $result = $lvalue->eq($rvalue);
1159  
1160 # 0
1161  
1162 =back
1163  
1164 =over 4
1165  
1166 =item eq example 4
1167  
1168 package main;
1169  
1170 use Venus::Array;
1171 use Venus::Hash;
1172  
1173 my $lvalue = Venus::Array->new;
1174 my $rvalue = Venus::Hash->new;
1175  
1176 my $result = $lvalue->eq($rvalue);
1177  
1178 # 0
1179  
1180 =back
1181  
1182 =over 4
1183  
1184 =item eq example 5
1185  
1186 package main;
1187  
1188 use Venus::Array;
1189 use Venus::Number;
1190  
1191 my $lvalue = Venus::Array->new;
1192 my $rvalue = Venus::Number->new;
1193  
1194 my $result = $lvalue->eq($rvalue);
1195  
1196 # 0
1197  
1198 =back
1199  
1200 =over 4
1201  
1202 =item eq example 6
1203  
1204 package main;
1205  
1206 use Venus::Array;
1207 use Venus::Regexp;
1208  
1209 my $lvalue = Venus::Array->new;
1210 my $rvalue = Venus::Regexp->new;
1211  
1212 my $result = $lvalue->eq($rvalue);
1213  
1214 # 0
1215  
1216 =back
1217  
1218 =over 4
1219  
1220 =item eq example 7
1221  
1222 package main;
1223  
1224 use Venus::Array;
1225 use Venus::Scalar;
1226  
1227 my $lvalue = Venus::Array->new;
1228 my $rvalue = Venus::Scalar->new;
1229  
1230 my $result = $lvalue->eq($rvalue);
1231  
1232 # 0
1233  
1234 =back
1235  
1236 =over 4
1237  
1238 =item eq example 8
1239  
1240 package main;
1241  
1242 use Venus::Array;
1243 use Venus::String;
1244  
1245 my $lvalue = Venus::Array->new;
1246 my $rvalue = Venus::String->new;
1247  
1248 my $result = $lvalue->eq($rvalue);
1249  
1250 # 0
1251  
1252 =back
1253  
1254 =over 4
1255  
1256 =item eq example 9
1257  
1258 package main;
1259  
1260 use Venus::Array;
1261 use Venus::Undef;
1262  
1263 my $lvalue = Venus::Array->new;
1264 my $rvalue = Venus::Undef->new;
1265  
1266 my $result = $lvalue->eq($rvalue);
1267  
1268 # 0
1269  
1270 =back
1271  
1272 =cut
1273  
1274 =head2 exists
1275  
1276 exists(number $index) (boolean)
1277  
1278 The exists method returns true if the element at the index specified exists,
1279 otherwise it returns false.
1280  
1281 I<Since C<0.01>>
1282  
1283 =over 4
1284  
1285 =item exists example 1
1286  
1287 # given: synopsis;
1288  
1289 my $exists = $array->exists(0);
1290  
1291 # 1
1292  
1293 =back
1294  
1295 =cut
1296  
1297 =head2 find
1298  
1299 find(string @keys) (any)
1300  
1301 The find method traverses the data structure using the keys and indices
1302 provided, returning the value found or undef. In list-context, this method
1303 returns a tuple, i.e. the value found and boolean representing whether the
1304 match was successful.
1305  
1306 I<Since C<0.01>>
1307  
1308 =over 4
1309  
1310 =item find example 1
1311  
1312 package main;
1313  
1314 use Venus::Array;
1315  
1316 my $array = Venus::Array->new([{'foo' => {'bar' => 'baz'}}, 'bar', ['baz']]);
1317  
1318 my $find = $array->find(0, 'foo');
1319  
1320 # { bar => "baz" }
1321  
1322 =back
1323  
1324 =over 4
1325  
1326 =item find example 2
1327  
1328 package main;
1329  
1330 use Venus::Array;
1331  
1332 my $array = Venus::Array->new([{'foo' => {'bar' => 'baz'}}, 'bar', ['baz']]);
1333  
1334 my $find = $array->find(0, 'foo', 'bar');
1335  
1336 # "baz"
1337  
1338 =back
1339  
1340 =over 4
1341  
1342 =item find example 3
1343  
1344 package main;
1345  
1346 use Venus::Array;
1347  
1348 my $array = Venus::Array->new([{'foo' => {'bar' => 'baz'}}, 'bar', ['baz']]);
1349  
1350 my $find = $array->find(2, 0);
1351  
1352 # "baz"
1353  
1354 =back
1355  
1356 =cut
1357  
1358 =head2 first
1359  
1360 first() (any)
1361  
1362 The first method returns the value of the first element.
1363  
1364 I<Since C<0.01>>
1365  
1366 =over 4
1367  
1368 =item first example 1
1369  
1370 # given: synopsis;
1371  
1372 my $first = $array->first;
1373  
1374 # 1
1375  
1376 =back
1377  
1378 =cut
1379  
1380 =head2 ge
1381  
1382 ge(any $arg) (boolean)
1383  
1384 The ge method performs a I<"greater-than-or-equal-to"> operation using the
1385 argument provided.
1386  
1387 I<Since C<0.08>>
1388  
1389 =over 4
1390  
1391 =item ge example 1
1392  
1393 package main;
1394  
1395 use Venus::Array;
1396  
1397 my $lvalue = Venus::Array->new;
1398 my $rvalue = Venus::Array->new;
1399  
1400 my $result = $lvalue->ge($rvalue);
1401  
1402 # 1
1403  
1404 =back
1405  
1406 =over 4
1407  
1408 =item ge example 2
1409  
1410 package main;
1411  
1412 use Venus::Array;
1413 use Venus::Code;
1414  
1415 my $lvalue = Venus::Array->new;
1416 my $rvalue = Venus::Code->new;
1417  
1418 my $result = $lvalue->ge($rvalue);
1419  
1420 # 0
1421  
1422 =back
1423  
1424 =over 4
1425  
1426 =item ge example 3
1427  
1428 package main;
1429  
1430 use Venus::Array;
1431 use Venus::Float;
1432  
1433 my $lvalue = Venus::Array->new;
1434 my $rvalue = Venus::Float->new;
1435  
1436 my $result = $lvalue->ge($rvalue);
1437  
1438 # 1
1439  
1440 =back
1441  
1442 =over 4
1443  
1444 =item ge example 4
1445  
1446 package main;
1447  
1448 use Venus::Array;
1449 use Venus::Hash;
1450  
1451 my $lvalue = Venus::Array->new;
1452 my $rvalue = Venus::Hash->new;
1453  
1454 my $result = $lvalue->ge($rvalue);
1455  
1456 # 0
1457  
1458 =back
1459  
1460 =over 4
1461  
1462 =item ge example 5
1463  
1464 package main;
1465  
1466 use Venus::Array;
1467 use Venus::Number;
1468  
1469 my $lvalue = Venus::Array->new;
1470 my $rvalue = Venus::Number->new;
1471  
1472 my $result = $lvalue->ge($rvalue);
1473  
1474 # 1
1475  
1476 =back
1477  
1478 =over 4
1479  
1480 =item ge example 6
1481  
1482 package main;
1483  
1484 use Venus::Array;
1485 use Venus::Regexp;
1486  
1487 my $lvalue = Venus::Array->new;
1488 my $rvalue = Venus::Regexp->new;
1489  
1490 my $result = $lvalue->ge($rvalue);
1491  
1492 # 0
1493  
1494 =back
1495  
1496 =over 4
1497  
1498 =item ge example 7
1499  
1500 package main;
1501  
1502 use Venus::Array;
1503 use Venus::Scalar;
1504  
1505 my $lvalue = Venus::Array->new;
1506 my $rvalue = Venus::Scalar->new;
1507  
1508 my $result = $lvalue->ge($rvalue);
1509  
1510 # 0
1511  
1512 =back
1513  
1514 =over 4
1515  
1516 =item ge example 8
1517  
1518 package main;
1519  
1520 use Venus::Array;
1521 use Venus::String;
1522  
1523 my $lvalue = Venus::Array->new;
1524 my $rvalue = Venus::String->new;
1525  
1526 my $result = $lvalue->ge($rvalue);
1527  
1528 # 1
1529  
1530 =back
1531  
1532 =over 4
1533  
1534 =item ge example 9
1535  
1536 package main;
1537  
1538 use Venus::Array;
1539 use Venus::Undef;
1540  
1541 my $lvalue = Venus::Array->new;
1542 my $rvalue = Venus::Undef->new;
1543  
1544 my $result = $lvalue->ge($rvalue);
1545  
1546 # 1
1547  
1548 =back
1549  
1550 =cut
1551  
1552 =head2 gele
1553  
1554 gele(any $arg1, any $arg2) (boolean)
1555  
1556 The gele method performs a I<"greater-than-or-equal-to"> operation on the 1st
1557 argument, and I<"lesser-than-or-equal-to"> operation on the 2nd argument.
1558  
1559 I<Since C<0.08>>
1560  
1561 =over 4
1562  
1563 =item gele example 1
1564  
1565 package main;
1566  
1567 use Venus::Array;
1568  
1569 my $lvalue = Venus::Array->new;
1570 my $rvalue = Venus::Array->new;
1571  
1572 my $result = $lvalue->gele($rvalue);
1573  
1574 # 0
1575  
1576 =back
1577  
1578 =over 4
1579  
1580 =item gele example 2
1581  
1582 package main;
1583  
1584 use Venus::Array;
1585 use Venus::Code;
1586  
1587 my $lvalue = Venus::Array->new;
1588 my $rvalue = Venus::Code->new;
1589  
1590 my $result = $lvalue->gele($rvalue);
1591  
1592 # 0
1593  
1594 =back
1595  
1596 =over 4
1597  
1598 =item gele example 3
1599  
1600 package main;
1601  
1602 use Venus::Array;
1603 use Venus::Float;
1604  
1605 my $lvalue = Venus::Array->new;
1606 my $rvalue = Venus::Float->new;
1607  
1608 my $result = $lvalue->gele($rvalue);
1609  
1610 # 0
1611  
1612 =back
1613  
1614 =over 4
1615  
1616 =item gele example 4
1617  
1618 package main;
1619  
1620 use Venus::Array;
1621 use Venus::Hash;
1622  
1623 my $lvalue = Venus::Array->new;
1624 my $rvalue = Venus::Hash->new;
1625  
1626 my $result = $lvalue->gele($rvalue);
1627  
1628 # 0
1629  
1630 =back
1631  
1632 =over 4
1633  
1634 =item gele example 5
1635  
1636 package main;
1637  
1638 use Venus::Array;
1639 use Venus::Number;
1640  
1641 my $lvalue = Venus::Array->new;
1642 my $rvalue = Venus::Number->new;
1643  
1644 my $result = $lvalue->gele($rvalue);
1645  
1646 # 0
1647  
1648 =back
1649  
1650 =over 4
1651  
1652 =item gele example 6
1653  
1654 package main;
1655  
1656 use Venus::Array;
1657 use Venus::Regexp;
1658  
1659 my $lvalue = Venus::Array->new;
1660 my $rvalue = Venus::Regexp->new;
1661  
1662 my $result = $lvalue->gele($rvalue);
1663  
1664 # 0
1665  
1666 =back
1667  
1668 =over 4
1669  
1670 =item gele example 7
1671  
1672 package main;
1673  
1674 use Venus::Array;
1675 use Venus::Scalar;
1676  
1677 my $lvalue = Venus::Array->new;
1678 my $rvalue = Venus::Scalar->new;
1679  
1680 my $result = $lvalue->gele($rvalue);
1681  
1682 # 0
1683  
1684 =back
1685  
1686 =over 4
1687  
1688 =item gele example 8
1689  
1690 package main;
1691  
1692 use Venus::Array;
1693 use Venus::String;
1694  
1695 my $lvalue = Venus::Array->new;
1696 my $rvalue = Venus::String->new;
1697  
1698 my $result = $lvalue->gele($rvalue);
1699  
1700 # 0
1701  
1702 =back
1703  
1704 =over 4
1705  
1706 =item gele example 9
1707  
1708 package main;
1709  
1710 use Venus::Array;
1711 use Venus::Undef;
1712  
1713 my $lvalue = Venus::Array->new;
1714 my $rvalue = Venus::Undef->new;
1715  
1716 my $result = $lvalue->gele($rvalue);
1717  
1718 # 0
1719  
1720 =back
1721  
1722 =cut
1723  
1724 =head2 gets
1725  
1726 gets(string @args) (arrayref)
1727  
1728 The gets method select values from within the underlying data structure using
1729 L<Venus::Array/path>, where each argument is a selector, returns all the values
1730 selected. Returns a list in list context.
1731  
1732 I<Since C<4.15>>
1733  
1734 =over 4
1735  
1736 =item gets example 1
1737  
1738 package main;
1739  
1740 use Venus::Array;
1741  
1742 my $array = Venus::Array->new(['foo', {'bar' => 'baz'}, 'bar', ['baz']]);
1743  
1744 my $gets = $array->gets('3', '1.bar');
1745  
1746 # [['baz'], 'baz']
1747  
1748 =back
1749  
1750 =over 4
1751  
1752 =item gets example 2
1753  
1754 package main;
1755  
1756 use Venus::Array;
1757  
1758 my $array = Venus::Array->new(['foo', {'bar' => 'baz'}, 'bar', ['baz']]);
1759  
1760 my ($baz, $one_bar) = $array->gets('3', '1.bar');
1761  
1762 # (['baz'], 'baz')
1763  
1764 =back
1765  
1766 =over 4
1767  
1768 =item gets example 3
1769  
1770 package main;
1771  
1772 use Venus::Array;
1773  
1774 my $array = Venus::Array->new(['foo', {'bar' => 'baz'}, 'bar', ['baz']]);
1775  
1776 my $gets = $array->gets('3', '1.bar', '1.bar.baz');
1777  
1778 # [['baz'], 'baz', undef]
1779  
1780 =back
1781  
1782 =cut
1783  
1784 =head2 grep
1785  
1786 grep(coderef $code) (arrayref)
1787  
1788 The grep method executes a callback for each element in the array passing the
1789 value as an argument, returning a new array reference containing the elements
1790 for which the returned true. This method can return a list of values in
1791 list-context.
1792  
1793 I<Since C<0.01>>
1794  
1795 =over 4
1796  
1797 =item grep example 1
1798  
1799 # given: synopsis;
1800  
1801 my $grep = $array->grep(sub {
1802 $_ > 3
1803 });
1804  
1805 # [4..9]
1806  
1807 =back
1808  
1809 =over 4
1810  
1811 =item grep example 2
1812  
1813 # given: synopsis;
1814  
1815 my $grep = $array->grep(sub {
1816 my ($key, $value) = @_;
1817  
1818 $value > 3
1819 });
1820  
1821 # [4..9]
1822  
1823 =back
1824  
1825 =cut
1826  
1827 =head2 gt
1828  
1829 gt(any $arg) (boolean)
1830  
1831 The gt method performs a I<"greater-than"> operation using the argument provided.
1832  
1833 I<Since C<0.08>>
1834  
1835 =over 4
1836  
1837 =item gt example 1
1838  
1839 package main;
1840  
1841 use Venus::Array;
1842  
1843 my $lvalue = Venus::Array->new;
1844 my $rvalue = Venus::Array->new;
1845  
1846 my $result = $lvalue->gt($rvalue);
1847  
1848 # 0
1849  
1850 =back
1851  
1852 =over 4
1853  
1854 =item gt example 2
1855  
1856 package main;
1857  
1858 use Venus::Array;
1859 use Venus::Code;
1860  
1861 my $lvalue = Venus::Array->new;
1862 my $rvalue = Venus::Code->new;
1863  
1864 my $result = $lvalue->gt($rvalue);
1865  
1866 # 0
1867  
1868 =back
1869  
1870 =over 4
1871  
1872 =item gt example 3
1873  
1874 package main;
1875  
1876 use Venus::Array;
1877 use Venus::Float;
1878  
1879 my $lvalue = Venus::Array->new;
1880 my $rvalue = Venus::Float->new;
1881  
1882 my $result = $lvalue->gt($rvalue);
1883  
1884 # 1
1885  
1886 =back
1887  
1888 =over 4
1889  
1890 =item gt example 4
1891  
1892 package main;
1893  
1894 use Venus::Array;
1895 use Venus::Hash;
1896  
1897 my $lvalue = Venus::Array->new;
1898 my $rvalue = Venus::Hash->new;
1899  
1900 my $result = $lvalue->gt($rvalue);
1901  
1902 # 0
1903  
1904 =back
1905  
1906 =over 4
1907  
1908 =item gt example 5
1909  
1910 package main;
1911  
1912 use Venus::Array;
1913 use Venus::Number;
1914  
1915 my $lvalue = Venus::Array->new;
1916 my $rvalue = Venus::Number->new;
1917  
1918 my $result = $lvalue->gt($rvalue);
1919  
1920 # 1
1921  
1922 =back
1923  
1924 =over 4
1925  
1926 =item gt example 6
1927  
1928 package main;
1929  
1930 use Venus::Array;
1931 use Venus::Regexp;
1932  
1933 my $lvalue = Venus::Array->new;
1934 my $rvalue = Venus::Regexp->new;
1935  
1936 my $result = $lvalue->gt($rvalue);
1937  
1938 # 0
1939  
1940 =back
1941  
1942 =over 4
1943  
1944 =item gt example 7
1945  
1946 package main;
1947  
1948 use Venus::Array;
1949 use Venus::Scalar;
1950  
1951 my $lvalue = Venus::Array->new;
1952 my $rvalue = Venus::Scalar->new;
1953  
1954 my $result = $lvalue->gt($rvalue);
1955  
1956 # 0
1957  
1958 =back
1959  
1960 =over 4
1961  
1962 =item gt example 8
1963  
1964 package main;
1965  
1966 use Venus::Array;
1967 use Venus::String;
1968  
1969 my $lvalue = Venus::Array->new;
1970 my $rvalue = Venus::String->new;
1971  
1972 my $result = $lvalue->gt($rvalue);
1973  
1974 # 1
1975  
1976 =back
1977  
1978 =over 4
1979  
1980 =item gt example 9
1981  
1982 package main;
1983  
1984 use Venus::Array;
1985 use Venus::Undef;
1986  
1987 my $lvalue = Venus::Array->new;
1988 my $rvalue = Venus::Undef->new;
1989  
1990 my $result = $lvalue->gt($rvalue);
1991  
1992 # 1
1993  
1994 =back
1995  
1996 =cut
1997  
1998 =head2 gtlt
1999  
2000 gtlt(any $arg1, any $arg2) (boolean)
2001  
2002 The gtlt method performs a I<"greater-than"> operation on the 1st argument, and
2003 I<"lesser-than"> operation on the 2nd argument.
2004  
2005 I<Since C<0.08>>
2006  
2007 =over 4
2008  
2009 =item gtlt example 1
2010  
2011 package main;
2012  
2013 use Venus::Array;
2014  
2015 my $lvalue = Venus::Array->new;
2016 my $rvalue = Venus::Array->new;
2017  
2018 my $result = $lvalue->gtlt($rvalue);
2019  
2020 # 0
2021  
2022 =back
2023  
2024 =over 4
2025  
2026 =item gtlt example 2
2027  
2028 package main;
2029  
2030 use Venus::Array;
2031 use Venus::Code;
2032  
2033 my $lvalue = Venus::Array->new;
2034 my $rvalue = Venus::Code->new;
2035  
2036 my $result = $lvalue->gtlt($rvalue);
2037  
2038 # 0
2039  
2040 =back
2041  
2042 =over 4
2043  
2044 =item gtlt example 3
2045  
2046 package main;
2047  
2048 use Venus::Array;
2049 use Venus::Float;
2050  
2051 my $lvalue = Venus::Array->new;
2052 my $rvalue = Venus::Float->new;
2053  
2054 my $result = $lvalue->gtlt($rvalue);
2055  
2056 # 0
2057  
2058 =back
2059  
2060 =over 4
2061  
2062 =item gtlt example 4
2063  
2064 package main;
2065  
2066 use Venus::Array;
2067 use Venus::Hash;
2068  
2069 my $lvalue = Venus::Array->new;
2070 my $rvalue = Venus::Hash->new;
2071  
2072 my $result = $lvalue->gtlt($rvalue);
2073  
2074 # 0
2075  
2076 =back
2077  
2078 =over 4
2079  
2080 =item gtlt example 5
2081  
2082 package main;
2083  
2084 use Venus::Array;
2085 use Venus::Number;
2086  
2087 my $lvalue = Venus::Array->new;
2088 my $rvalue = Venus::Number->new;
2089  
2090 my $result = $lvalue->gtlt($rvalue);
2091  
2092 # 0
2093  
2094 =back
2095  
2096 =over 4
2097  
2098 =item gtlt example 6
2099  
2100 package main;
2101  
2102 use Venus::Array;
2103 use Venus::Regexp;
2104  
2105 my $lvalue = Venus::Array->new;
2106 my $rvalue = Venus::Regexp->new;
2107  
2108 my $result = $lvalue->gtlt($rvalue);
2109  
2110 # 0
2111  
2112 =back
2113  
2114 =over 4
2115  
2116 =item gtlt example 7
2117  
2118 package main;
2119  
2120 use Venus::Array;
2121 use Venus::Scalar;
2122  
2123 my $lvalue = Venus::Array->new;
2124 my $rvalue = Venus::Scalar->new;
2125  
2126 my $result = $lvalue->gtlt($rvalue);
2127  
2128 # 0
2129  
2130 =back
2131  
2132 =over 4
2133  
2134 =item gtlt example 8
2135  
2136 package main;
2137  
2138 use Venus::Array;
2139 use Venus::String;
2140  
2141 my $lvalue = Venus::Array->new;
2142 my $rvalue = Venus::String->new;
2143  
2144 my $result = $lvalue->gtlt($rvalue);
2145  
2146 # 0
2147  
2148 =back
2149  
2150 =over 4
2151  
2152 =item gtlt example 9
2153  
2154 package main;
2155  
2156 use Venus::Array;
2157 use Venus::Undef;
2158  
2159 my $lvalue = Venus::Array->new;
2160 my $rvalue = Venus::Undef->new;
2161  
2162 my $result = $lvalue->gtlt($rvalue);
2163  
2164 # 0
2165  
2166 =back
2167  
2168 =cut
2169  
2170 =head2 head
2171  
2172 head(number $size) (arrayref)
2173  
2174 The head method returns the topmost elements, limited by the desired size
2175 specified.
2176  
2177 I<Since C<1.23>>
2178  
2179 =over 4
2180  
2181 =item head example 1
2182  
2183 # given: synopsis;
2184  
2185 my $head = $array->head;
2186  
2187 # [1]
2188  
2189 =back
2190  
2191 =over 4
2192  
2193 =item head example 2
2194  
2195 # given: synopsis;
2196  
2197 my $head = $array->head(1);
2198  
2199 # [1]
2200  
2201 =back
2202  
2203 =over 4
2204  
2205 =item head example 3
2206  
2207 # given: synopsis;
2208  
2209 my $head = $array->head(2);
2210  
2211 # [1,2]
2212  
2213 =back
2214  
2215 =over 4
2216  
2217 =item head example 4
2218  
2219 # given: synopsis;
2220  
2221 my $head = $array->head(5);
2222  
2223 # [1..5]
2224  
2225 =back
2226  
2227 =over 4
2228  
2229 =item head example 5
2230  
2231 # given: synopsis;
2232  
2233 my $head = $array->head(20);
2234  
2235 # [1..9]
2236  
2237 =back
2238  
2239 =cut
2240  
2241 =head2 iterator
2242  
2243 iterator() (coderef)
2244  
2245 The iterator method returns a code reference which can be used to iterate over
2246 the array. Each time the iterator is executed it will return the next element
2247 in the array until all elements have been seen, at which point the iterator
2248 will return an undefined value. This method can return a tuple with the key and
2249 value in list-context.
2250  
2251 I<Since C<0.01>>
2252  
2253 =over 4
2254  
2255 =item iterator example 1
2256  
2257 # given: synopsis;
2258  
2259 my $iterator = $array->iterator;
2260  
2261 # sub { ... }
2262  
2263 # while (my $value = $iterator->()) {
2264 # say $value; # 1
2265 # }
2266  
2267 =back
2268  
2269 =over 4
2270  
2271 =item iterator example 2
2272  
2273 # given: synopsis;
2274  
2275 my $iterator = $array->iterator;
2276  
2277 # sub { ... }
2278  
2279 # while (grep defined, my ($key, $value) = $iterator->()) {
2280 # say $value; # 1
2281 # }
2282  
2283 =back
2284  
2285 =cut
2286  
2287 =head2 join
2288  
2289 join(string $seperator) (string)
2290  
2291 The join method returns a string consisting of all the elements in the array
2292 joined by the join-string specified by the argument. Note: If the argument is
2293 omitted, an empty string will be used as the join-string.
2294  
2295 I<Since C<0.01>>
2296  
2297 =over 4
2298  
2299 =item join example 1
2300  
2301 # given: synopsis;
2302  
2303 my $join = $array->join;
2304  
2305 # 123456789
2306  
2307 =back
2308  
2309 =over 4
2310  
2311 =item join example 2
2312  
2313 # given: synopsis;
2314  
2315 my $join = $array->join(', ');
2316  
2317 # "1, 2, 3, 4, 5, 6, 7, 8, 9"
2318  
2319 =back
2320  
2321 =cut
2322  
2323 =head2 keyed
2324  
2325 keyed(string @keys) (hashref)
2326  
2327 The keyed method returns a hash reference where the arguments become the keys,
2328 and the elements of the array become the values.
2329  
2330 I<Since C<0.01>>
2331  
2332 =over 4
2333  
2334 =item keyed example 1
2335  
2336 package main;
2337  
2338 use Venus::Array;
2339  
2340 my $array = Venus::Array->new([1..4]);
2341  
2342 my $keyed = $array->keyed('a'..'d');
2343  
2344 # { a => 1, b => 2, c => 3, d => 4 }
2345  
2346 =back
2347  
2348 =cut
2349  
2350 =head2 keys
2351  
2352 keys() (arrayref)
2353  
2354 The keys method returns an array reference consisting of the indicies of the
2355 array.
2356  
2357 I<Since C<0.01>>
2358  
2359 =over 4
2360  
2361 =item keys example 1
2362  
2363 # given: synopsis;
2364  
2365 my $keys = $array->keys;
2366  
2367 # [0..8]
2368  
2369 =back
2370  
2371 =cut
2372  
2373 =head2 last
2374  
2375 last() (any)
2376  
2377 The last method returns the value of the last element in the array.
2378  
2379 I<Since C<0.01>>
2380  
2381 =over 4
2382  
2383 =item last example 1
2384  
2385 # given: synopsis;
2386  
2387 my $last = $array->last;
2388  
2389 # 9
2390  
2391 =back
2392  
2393 =cut
2394  
2395 =head2 le
2396  
2397 le(any $arg) (boolean)
2398  
2399 The le method performs a I<"lesser-than-or-equal-to"> operation using the
2400 argument provided.
2401  
2402 I<Since C<0.08>>
2403  
2404 =over 4
2405  
2406 =item le example 1
2407  
2408 package main;
2409  
2410 use Venus::Array;
2411  
2412 my $lvalue = Venus::Array->new;
2413 my $rvalue = Venus::Array->new;
2414  
2415 my $result = $lvalue->le($rvalue);
2416  
2417 # 1
2418  
2419 =back
2420  
2421 =over 4
2422  
2423 =item le example 2
2424  
2425 package main;
2426  
2427 use Venus::Array;
2428 use Venus::Code;
2429  
2430 my $lvalue = Venus::Array->new;
2431 my $rvalue = Venus::Code->new;
2432  
2433 my $result = $lvalue->le($rvalue);
2434  
2435 # 1
2436  
2437 =back
2438  
2439 =over 4
2440  
2441 =item le example 3
2442  
2443 package main;
2444  
2445 use Venus::Array;
2446 use Venus::Float;
2447  
2448 my $lvalue = Venus::Array->new;
2449 my $rvalue = Venus::Float->new;
2450  
2451 my $result = $lvalue->le($rvalue);
2452  
2453 # 0
2454  
2455 =back
2456  
2457 =over 4
2458  
2459 =item le example 4
2460  
2461 package main;
2462  
2463 use Venus::Array;
2464 use Venus::Hash;
2465  
2466 my $lvalue = Venus::Array->new;
2467 my $rvalue = Venus::Hash->new;
2468  
2469 my $result = $lvalue->le($rvalue);
2470  
2471 # 0
2472  
2473 =back
2474  
2475 =over 4
2476  
2477 =item le example 5
2478  
2479 package main;
2480  
2481 use Venus::Array;
2482 use Venus::Number;
2483  
2484 my $lvalue = Venus::Array->new;
2485 my $rvalue = Venus::Number->new;
2486  
2487 my $result = $lvalue->le($rvalue);
2488  
2489 # 0
2490  
2491 =back
2492  
2493 =over 4
2494  
2495 =item le example 6
2496  
2497 package main;
2498  
2499 use Venus::Array;
2500 use Venus::Regexp;
2501  
2502 my $lvalue = Venus::Array->new;
2503 my $rvalue = Venus::Regexp->new;
2504  
2505 my $result = $lvalue->le($rvalue);
2506  
2507 # 1
2508  
2509 =back
2510  
2511 =over 4
2512  
2513 =item le example 7
2514  
2515 package main;
2516  
2517 use Venus::Array;
2518 use Venus::Scalar;
2519  
2520 my $lvalue = Venus::Array->new;
2521 my $rvalue = Venus::Scalar->new;
2522  
2523 my $result = $lvalue->le($rvalue);
2524  
2525 # 0
2526  
2527 =back
2528  
2529 =over 4
2530  
2531 =item le example 8
2532  
2533 package main;
2534  
2535 use Venus::Array;
2536 use Venus::String;
2537  
2538 my $lvalue = Venus::Array->new;
2539 my $rvalue = Venus::String->new;
2540  
2541 my $result = $lvalue->le($rvalue);
2542  
2543 # 0
2544  
2545 =back
2546  
2547 =over 4
2548  
2549 =item le example 9
2550  
2551 package main;
2552  
2553 use Venus::Array;
2554 use Venus::Undef;
2555  
2556 my $lvalue = Venus::Array->new;
2557 my $rvalue = Venus::Undef->new;
2558  
2559 my $result = $lvalue->le($rvalue);
2560  
2561 # 0
2562  
2563 =back
2564  
2565 =cut
2566  
2567 =head2 length
2568  
2569 length() (number)
2570  
2571 The length method returns the number of elements within the array, and is an
2572 alias for the L</count> method.
2573  
2574 I<Since C<0.08>>
2575  
2576 =over 4
2577  
2578 =item length example 1
2579  
2580 # given: synopsis;
2581  
2582 my $length = $array->length;
2583  
2584 # 9
2585  
2586 =back
2587  
2588 =cut
2589  
2590 =head2 list
2591  
2592 list() (any)
2593  
2594 The list method returns a shallow copy of the underlying array reference as an
2595 array reference.
2596  
2597 I<Since C<0.01>>
2598  
2599 =over 4
2600  
2601 =item list example 1
2602  
2603 # given: synopsis;
2604  
2605 my $list = $array->list;
2606  
2607 # 9
2608  
2609 =back
2610  
2611 =over 4
2612  
2613 =item list example 2
2614  
2615 # given: synopsis;
2616  
2617 my @list = $array->list;
2618  
2619 # (1..9)
2620  
2621 =back
2622  
2623 =cut
2624  
2625 =head2 lt
2626  
2627 lt(any $arg) (boolean)
2628  
2629 The lt method performs a I<"lesser-than"> operation using the argument provided.
2630  
2631 I<Since C<0.08>>
2632  
2633 =over 4
2634  
2635 =item lt example 1
2636  
2637 package main;
2638  
2639 use Venus::Array;
2640  
2641 my $lvalue = Venus::Array->new;
2642 my $rvalue = Venus::Array->new;
2643  
2644 my $result = $lvalue->lt($rvalue);
2645  
2646 # 0
2647  
2648 =back
2649  
2650 =over 4
2651  
2652 =item lt example 2
2653  
2654 package main;
2655  
2656 use Venus::Array;
2657 use Venus::Code;
2658  
2659 my $lvalue = Venus::Array->new;
2660 my $rvalue = Venus::Code->new;
2661  
2662 my $result = $lvalue->lt($rvalue);
2663  
2664 # 1
2665  
2666 =back
2667  
2668 =over 4
2669  
2670 =item lt example 3
2671  
2672 package main;
2673  
2674 use Venus::Array;
2675 use Venus::Float;
2676  
2677 my $lvalue = Venus::Array->new;
2678 my $rvalue = Venus::Float->new;
2679  
2680 my $result = $lvalue->lt($rvalue);
2681  
2682 # 0
2683  
2684 =back
2685  
2686 =over 4
2687  
2688 =item lt example 4
2689  
2690 package main;
2691  
2692 use Venus::Array;
2693 use Venus::Hash;
2694  
2695 my $lvalue = Venus::Array->new;
2696 my $rvalue = Venus::Hash->new;
2697  
2698 my $result = $lvalue->lt($rvalue);
2699  
2700 # 0
2701  
2702 =back
2703  
2704 =over 4
2705  
2706 =item lt example 5
2707  
2708 package main;
2709  
2710 use Venus::Array;
2711 use Venus::Number;
2712  
2713 my $lvalue = Venus::Array->new;
2714 my $rvalue = Venus::Number->new;
2715  
2716 my $result = $lvalue->lt($rvalue);
2717  
2718 # 0
2719  
2720 =back
2721  
2722 =over 4
2723  
2724 =item lt example 6
2725  
2726 package main;
2727  
2728 use Venus::Array;
2729 use Venus::Regexp;
2730  
2731 my $lvalue = Venus::Array->new;
2732 my $rvalue = Venus::Regexp->new;
2733  
2734 my $result = $lvalue->lt($rvalue);
2735  
2736 # 1
2737  
2738 =back
2739  
2740 =over 4
2741  
2742 =item lt example 7
2743  
2744 package main;
2745  
2746 use Venus::Array;
2747 use Venus::Scalar;
2748  
2749 my $lvalue = Venus::Array->new;
2750 my $rvalue = Venus::Scalar->new;
2751  
2752 my $result = $lvalue->lt($rvalue);
2753  
2754 # 0
2755  
2756 =back
2757  
2758 =over 4
2759  
2760 =item lt example 8
2761  
2762 package main;
2763  
2764 use Venus::Array;
2765 use Venus::String;
2766  
2767 my $lvalue = Venus::Array->new;
2768 my $rvalue = Venus::String->new;
2769  
2770 my $result = $lvalue->lt($rvalue);
2771  
2772 # 0
2773  
2774 =back
2775  
2776 =over 4
2777  
2778 =item lt example 9
2779  
2780 package main;
2781  
2782 use Venus::Array;
2783 use Venus::Undef;
2784  
2785 my $lvalue = Venus::Array->new;
2786 my $rvalue = Venus::Undef->new;
2787  
2788 my $result = $lvalue->lt($rvalue);
2789  
2790 # 0
2791  
2792 =back
2793  
2794 =cut
2795  
2796 =head2 map
2797  
2798 map(coderef $code) (arrayref)
2799  
2800 The map method iterates over each element in the array, executing the code
2801 reference supplied in the argument, passing the routine the value at the
2802 current position in the loop and returning a new array reference containing the
2803 elements for which the argument returns a value or non-empty list. This method
2804 can return a list of values in list-context.
2805  
2806 I<Since C<0.01>>
2807  
2808 =over 4
2809  
2810 =item map example 1
2811  
2812 # given: synopsis;
2813  
2814 my $map = $array->map(sub {
2815 $_ * 2
2816 });
2817  
2818 # [2, 4, 6, 8, 10, 12, 14, 16, 18]
2819  
2820 =back
2821  
2822 =over 4
2823  
2824 =item map example 2
2825  
2826 # given: synopsis;
2827  
2828 my $map = $array->map(sub {
2829 my ($key, $value) = @_;
2830  
2831 [$key, ($value * 2)]
2832 });
2833  
2834 # [
2835 # [0, 2],
2836 # [1, 4],
2837 # [2, 6],
2838 # [3, 8],
2839 # [4, 10],
2840 # [5, 12],
2841 # [6, 14],
2842 # [7, 16],
2843 # [8, 18],
2844 # ]
2845  
2846 =back
2847  
2848 =cut
2849  
2850 =head2 merge
2851  
2852 merge(arrayref @data) (arrayref)
2853  
2854 The merge method returns an array reference where the elements in the array and
2855 the elements in the argument(s) are merged. This operation performs a deep
2856 merge and clones the datasets to ensure no side-effects.
2857  
2858 I<Since C<3.30>>
2859  
2860 =over 4
2861  
2862 =item merge example 1
2863  
2864 # given: synopsis;
2865  
2866 my $merge = $array->merge([10..15]);
2867  
2868 # [10..15,7,8,9]
2869  
2870 =back
2871  
2872 =over 4
2873  
2874 =item merge example 2
2875  
2876 # given: synopsis;
2877  
2878 my $merge = $array->merge([1,2,{1..4},4..9]);
2879  
2880 # [1,2,{1..4},4..9]
2881  
2882 =back
2883  
2884 =cut
2885  
2886 =head2 ne
2887  
2888 ne(any $arg) (boolean)
2889  
2890 The ne method performs a I<"not-equal-to"> operation using the argument provided.
2891  
2892 I<Since C<0.08>>
2893  
2894 =over 4
2895  
2896 =item ne example 1
2897  
2898 package main;
2899  
2900 use Venus::Array;
2901  
2902 my $lvalue = Venus::Array->new;
2903 my $rvalue = Venus::Array->new;
2904  
2905 my $result = $lvalue->ne($rvalue);
2906  
2907 # 0
2908  
2909 =back
2910  
2911 =over 4
2912  
2913 =item ne example 2
2914  
2915 package main;
2916  
2917 use Venus::Array;
2918 use Venus::Code;
2919  
2920 my $lvalue = Venus::Array->new;
2921 my $rvalue = Venus::Code->new;
2922  
2923 my $result = $lvalue->ne($rvalue);
2924  
2925 # 1
2926  
2927 =back
2928  
2929 =over 4
2930  
2931 =item ne example 3
2932  
2933 package main;
2934  
2935 use Venus::Array;
2936 use Venus::Float;
2937  
2938 my $lvalue = Venus::Array->new;
2939 my $rvalue = Venus::Float->new;
2940  
2941 my $result = $lvalue->ne($rvalue);
2942  
2943 # 1
2944  
2945 =back
2946  
2947 =over 4
2948  
2949 =item ne example 4
2950  
2951 package main;
2952  
2953 use Venus::Array;
2954 use Venus::Hash;
2955  
2956 my $lvalue = Venus::Array->new;
2957 my $rvalue = Venus::Hash->new;
2958  
2959 my $result = $lvalue->ne($rvalue);
2960  
2961 # 1
2962  
2963 =back
2964  
2965 =over 4
2966  
2967 =item ne example 5
2968  
2969 package main;
2970  
2971 use Venus::Array;
2972 use Venus::Number;
2973  
2974 my $lvalue = Venus::Array->new;
2975 my $rvalue = Venus::Number->new;
2976  
2977 my $result = $lvalue->ne($rvalue);
2978  
2979 # 1
2980  
2981 =back
2982  
2983 =over 4
2984  
2985 =item ne example 6
2986  
2987 package main;
2988  
2989 use Venus::Array;
2990 use Venus::Regexp;
2991  
2992 my $lvalue = Venus::Array->new;
2993 my $rvalue = Venus::Regexp->new;
2994  
2995 my $result = $lvalue->ne($rvalue);
2996  
2997 # 1
2998  
2999 =back
3000  
3001 =over 4
3002  
3003 =item ne example 7
3004  
3005 package main;
3006  
3007 use Venus::Array;
3008 use Venus::Scalar;
3009  
3010 my $lvalue = Venus::Array->new;
3011 my $rvalue = Venus::Scalar->new;
3012  
3013 my $result = $lvalue->ne($rvalue);
3014  
3015 # 1
3016  
3017 =back
3018  
3019 =over 4
3020  
3021 =item ne example 8
3022  
3023 package main;
3024  
3025 use Venus::Array;
3026 use Venus::String;
3027  
3028 my $lvalue = Venus::Array->new;
3029 my $rvalue = Venus::String->new;
3030  
3031 my $result = $lvalue->ne($rvalue);
3032  
3033 # 1
3034  
3035 =back
3036  
3037 =over 4
3038  
3039 =item ne example 9
3040  
3041 package main;
3042  
3043 use Venus::Array;
3044 use Venus::Undef;
3045  
3046 my $lvalue = Venus::Array->new;
3047 my $rvalue = Venus::Undef->new;
3048  
3049 my $result = $lvalue->ne($rvalue);
3050  
3051 # 1
3052  
3053 =back
3054  
3055 =cut
3056  
3057 =head2 new
3058  
3059 new(any @args) (Venus::Array)
3060  
3061 The new method constructs an instance of the package.
3062  
3063 I<Since C<4.15>>
3064  
3065 =over 4
3066  
3067 =item new example 1
3068  
3069 package main;
3070  
3071 use Venus::Array;
3072  
3073 my $new = Venus::Array->new;
3074  
3075 # bless(..., "Venus::Array")
3076  
3077 =back
3078  
3079 =over 4
3080  
3081 =item new example 2
3082  
3083 package main;
3084  
3085 use Venus::Array;
3086  
3087 my $new = Venus::Array->new([1..9]);
3088  
3089 # bless(..., "Venus::Array")
3090  
3091 =back
3092  
3093 =over 4
3094  
3095 =item new example 3
3096  
3097 package main;
3098  
3099 use Venus::Array;
3100  
3101 my $new = Venus::Array->new(value => [1..9]);
3102  
3103 # bless(..., "Venus::Array")
3104  
3105 =back
3106  
3107 =cut
3108  
3109 =head2 none
3110  
3111 none(coderef $code) (boolean)
3112  
3113 The none method returns true if none of the elements in the array meet the
3114 criteria set by the operand and rvalue.
3115  
3116 I<Since C<0.01>>
3117  
3118 =over 4
3119  
3120 =item none example 1
3121  
3122 # given: synopsis;
3123  
3124 my $none = $array->none(sub {
3125 $_ < 1
3126 });
3127  
3128 # 1
3129  
3130 =back
3131  
3132 =over 4
3133  
3134 =item none example 2
3135  
3136 # given: synopsis;
3137  
3138 my $none = $array->none(sub {
3139 my ($key, $value) = @_;
3140  
3141 $value < 1
3142 });
3143  
3144 # 1
3145  
3146 =back
3147  
3148 =cut
3149  
3150 =head2 one
3151  
3152 one(coderef $code) (boolean)
3153  
3154 The one method returns true if only one of the elements in the array meet the
3155 criteria set by the operand and rvalue.
3156  
3157 I<Since C<0.01>>
3158  
3159 =over 4
3160  
3161 =item one example 1
3162  
3163 # given: synopsis;
3164  
3165 my $one = $array->one(sub {
3166 $_ == 1
3167 });
3168  
3169 # 1
3170  
3171 =back
3172  
3173 =over 4
3174  
3175 =item one example 2
3176  
3177 # given: synopsis;
3178  
3179 my $one = $array->one(sub {
3180 my ($key, $value) = @_;
3181  
3182 $value == 1
3183 });
3184  
3185 # 1
3186  
3187 =back
3188  
3189 =cut
3190  
3191 =head2 order
3192  
3193 order(number @indices) (Venus::Array)
3194  
3195 The order method reorders the array items based on the indices provided and
3196 returns the invocant.
3197  
3198 I<Since C<2.01>>
3199  
3200 =over 4
3201  
3202 =item order example 1
3203  
3204 # given: synopsis;
3205  
3206 my $order = $array->order;
3207  
3208 # bless({ value => [1..9] }, "Venus::Array")
3209  
3210 =back
3211  
3212 =over 4
3213  
3214 =item order example 2
3215  
3216 # given: synopsis;
3217  
3218 my $order = $array->order(8,7,6);
3219  
3220 # bless({ value => [9,8,7,1,2,3,4,5,6] }, "Venus::Array")
3221  
3222 =back
3223  
3224 =over 4
3225  
3226 =item order example 3
3227  
3228 # given: synopsis;
3229  
3230 my $order = $array->order(0,2,1);
3231  
3232 # bless({ value => [1,3,2,4,5,6,7,8,9] }, "Venus::Array")
3233  
3234 =back
3235  
3236 =cut
3237  
3238 =head2 pairs
3239  
3240 pairs() (arrayref)
3241  
3242 The pairs method is an alias to the pairs_array method. This method can return
3243 a list of values in list-context.
3244  
3245 I<Since C<0.01>>
3246  
3247 =over 4
3248  
3249 =item pairs example 1
3250  
3251 # given: synopsis;
3252  
3253 my $pairs = $array->pairs;
3254  
3255 # [
3256 # [0, 1],
3257 # [1, 2],
3258 # [2, 3],
3259 # [3, 4],
3260 # [4, 5],
3261 # [5, 6],
3262 # [6, 7],
3263 # [7, 8],
3264 # [8, 9],
3265 # ]
3266  
3267 =back
3268  
3269 =cut
3270  
3271 =head2 part
3272  
3273 part(coderef $code) (tuple[arrayref, arrayref])
3274  
3275 The part method iterates over each element in the array, executing the code
3276 reference supplied in the argument, using the result of the code reference to
3277 partition to array into two distinct array references. This method can return a
3278 list of values in list-context.
3279  
3280 I<Since C<0.01>>
3281  
3282 =over 4
3283  
3284 =item part example 1
3285  
3286 # given: synopsis;
3287  
3288 my $part = $array->part(sub {
3289 $_ > 5
3290 });
3291  
3292 # [[6..9], [1..5]]
3293  
3294 =back
3295  
3296 =over 4
3297  
3298 =item part example 2
3299  
3300 # given: synopsis;
3301  
3302 my $part = $array->part(sub {
3303 my ($key, $value) = @_;
3304  
3305 $value < 5
3306 });
3307  
3308 # [[1..4], [5..9]]
3309  
3310 =back
3311  
3312 =cut
3313  
3314 =head2 path
3315  
3316 path(string $expr) (any)
3317  
3318 The path method traverses the data structure using the path expr provided,
3319 returning the value found or undef. In list-context, this method returns a
3320 tuple, i.e. the value found and boolean representing whether the match was
3321 successful.
3322  
3323 I<Since C<0.01>>
3324  
3325 =over 4
3326  
3327 =item path example 1
3328  
3329 package main;
3330  
3331 use Venus::Array;
3332  
3333 my $array = Venus::Array->new([{'foo' => {'bar' => 'baz'}}, 'bar', ['baz']]);
3334  
3335 my $path = $array->path('/0/foo');
3336  
3337 # { bar => "baz" }
3338  
3339 =back
3340  
3341 =over 4
3342  
3343 =item path example 2
3344  
3345 package main;
3346  
3347 use Venus::Array;
3348  
3349 my $array = Venus::Array->new([{'foo' => {'bar' => 'baz'}}, 'bar', ['baz']]);
3350  
3351 my $path = $array->path('/0/foo/bar');
3352  
3353 # "baz"
3354  
3355 =back
3356  
3357 =over 4
3358  
3359 =item path example 3
3360  
3361 package main;
3362  
3363 use Venus::Array;
3364  
3365 my $array = Venus::Array->new([{'foo' => {'bar' => 'baz'}}, 'bar', ['baz']]);
3366  
3367 my $path = $array->path('/2/0');
3368  
3369 # "baz"
3370  
3371 =back
3372  
3373 =over 4
3374  
3375 =item path example 4
3376  
3377 package main;
3378  
3379 use Venus::Array;
3380  
3381 my $array = Venus::Array->new([{'foo' => {'bar' => 'baz'}}, 'bar', ['baz']]);
3382  
3383 my @path = $array->path('/3/0');
3384  
3385 # (undef, 0)
3386  
3387 =back
3388  
3389 =cut
3390  
3391 =head2 pop
3392  
3393 pop() (any)
3394  
3395 The pop method returns the last element of the array shortening it by one.
3396 Note, this method modifies the array.
3397  
3398 I<Since C<0.01>>
3399  
3400 =over 4
3401  
3402 =item pop example 1
3403  
3404 # given: synopsis;
3405  
3406 my $pop = $array->pop;
3407  
3408 # 9
3409  
3410 =back
3411  
3412 =cut
3413  
3414 =head2 push
3415  
3416 push(any @data) (arrayref)
3417  
3418 The push method appends the array by pushing the agruments onto it and returns
3419 itself.
3420  
3421 I<Since C<0.01>>
3422  
3423 =over 4
3424  
3425 =item push example 1
3426  
3427 # given: synopsis;
3428  
3429 my $push = $array->push(10);
3430  
3431 # [1..10]
3432  
3433 =back
3434  
3435 =cut
3436  
3437 =head2 puts
3438  
3439 puts(any @args) (arrayref)
3440  
3441 The puts method select values from within the underlying data structure using
3442 L<Venus::Array/path>, optionally assigning the value to the preceeding scalar
3443 reference and returns all the values selected.
3444  
3445 I<Since C<3.20>>
3446  
3447 =over 4
3448  
3449 =item puts example 1
3450  
3451 package main;
3452  
3453 use Venus::Array;
3454  
3455 my $array = Venus::Array->new([
3456 {
3457 fruit => "apple",
3458 size => "small",
3459 color => "red",
3460 },
3461 {
3462 fruit => "lemon",
3463 size => "large",
3464 color => "yellow",
3465 },
3466 ]);
3467  
3468 my $puts = $array->puts(undef, '0.fruit', undef, '1.fruit');
3469  
3470 # ["apple", "lemon"]
3471  
3472 =back
3473  
3474 =over 4
3475  
3476 =item puts example 2
3477  
3478 package main;
3479  
3480 use Venus::Array;
3481  
3482 my $array = Venus::Array->new([
3483 {
3484 fruit => "apple",
3485 size => "small",
3486 color => "red",
3487 },
3488 {
3489 fruit => "lemon",
3490 size => "large",
3491 color => "yellow",
3492 },
3493 ]);
3494  
3495 $array->puts(\my $fruit1, '0.fruit', \my $fruit2, '1.fruit');
3496  
3497 my $puts = [$fruit1, $fruit2];
3498  
3499 # ["apple", "lemon"]
3500  
3501 =back
3502  
3503 =over 4
3504  
3505 =item puts example 3
3506  
3507 package main;
3508  
3509 use Venus::Array;
3510  
3511 my $array = Venus::Array->new([
3512 {
3513 fruit => "apple",
3514 size => "small",
3515 color => "red",
3516 },
3517 {
3518 fruit => "lemon",
3519 size => "large",
3520 color => "yellow",
3521 },
3522 ]);
3523  
3524 $array->puts(
3525 \my $fruit1, '0.fruit',
3526 \my $fruit2, '1.fruit',
3527 \my $fruit3, '2.fruit',
3528 );
3529  
3530 my $puts = [$fruit1, $fruit2, $fruit3];
3531  
3532 # ["apple", "lemon", undef]
3533  
3534 =back
3535  
3536 =over 4
3537  
3538 =item puts example 4
3539  
3540 package main;
3541  
3542 use Venus::Array;
3543  
3544 my $array = Venus::Array->new([1..20]);
3545  
3546 $array->puts(
3547 \my $a, '0',
3548 \my $b, '1',
3549 \my $m, ['', '2:-2'],
3550 \my $x, '18',
3551 \my $y, '19',
3552 );
3553  
3554 my $puts = [$a, $b, $m, $x, $y];
3555  
3556 # [1, 2, [3..19], 19, 20]
3557  
3558 =back
3559  
3560 =over 4
3561  
3562 =item puts example 5
3563  
3564 package main;
3565  
3566 use Venus::Array;
3567  
3568 my $array = Venus::Array->new([[{1..4}, {1..4}]]);
3569  
3570 $array->puts(\my $a, '0');
3571  
3572 my $puts = $a;
3573  
3574 # [{1..4}, {1..4}]
3575  
3576 =back
3577  
3578 =cut
3579  
3580 =head2 random
3581  
3582 random() (any)
3583  
3584 The random method returns a random element from the array.
3585  
3586 I<Since C<0.01>>
3587  
3588 =over 4
3589  
3590 =item random example 1
3591  
3592 # given: synopsis;
3593  
3594 my $random = $array->random;
3595  
3596 # 2
3597  
3598 # my $random = $array->random;
3599  
3600 # 1
3601  
3602 =back
3603  
3604 =cut
3605  
3606 =head2 range
3607  
3608 range(number | string @args) (arrayref)
3609  
3610 The range method accepts a I<"range expression"> and returns the result of
3611 calling the L</slice> method with the computed range.
3612  
3613 I<Since C<2.55>>
3614  
3615 =over 4
3616  
3617 =item range example 1
3618  
3619 # given: synopsis
3620  
3621 package main;
3622  
3623 my $range = $array->range;
3624  
3625 # []
3626  
3627 =back
3628  
3629 =over 4
3630  
3631 =item range example 2
3632  
3633 # given: synopsis
3634  
3635 package main;
3636  
3637 my $range = $array->range(0);
3638  
3639 # [1]
3640  
3641 =back
3642  
3643 =over 4
3644  
3645 =item range example 3
3646  
3647 # given: synopsis
3648  
3649 package main;
3650  
3651 my $range = $array->range('0:');
3652  
3653 # [1..9]
3654  
3655 =back
3656  
3657 =over 4
3658  
3659 =item range example 4
3660  
3661 # given: synopsis
3662  
3663 package main;
3664  
3665 my $range = $array->range(':4');
3666  
3667 # [1..5]
3668  
3669 =back
3670  
3671 =over 4
3672  
3673 =item range example 5
3674  
3675 # given: synopsis
3676  
3677 package main;
3678  
3679 my $range = $array->range('8:');
3680  
3681 # [9]
3682  
3683 =back
3684  
3685 =over 4
3686  
3687 =item range example 6
3688  
3689 # given: synopsis
3690  
3691 package main;
3692  
3693 my $range = $array->range('4:');
3694  
3695 # [5..9]
3696  
3697 =back
3698  
3699 =over 4
3700  
3701 =item range example 7
3702  
3703 # given: synopsis
3704  
3705 package main;
3706  
3707 my $range = $array->range('0:2');
3708  
3709 # [1..3]
3710  
3711 =back
3712  
3713 =over 4
3714  
3715 =item range example 8
3716  
3717 # given: synopsis
3718  
3719 package main;
3720  
3721 my $range = $array->range('2:4');
3722  
3723 # [3..5]
3724  
3725 =back
3726  
3727 =over 4
3728  
3729 =item range example 9
3730  
3731 # given: synopsis
3732  
3733 package main;
3734  
3735 my $range = $array->range(0..3);
3736  
3737 # [1..4]
3738  
3739 =back
3740  
3741 =over 4
3742  
3743 =item range example 10
3744  
3745 # given: synopsis
3746  
3747 package main;
3748  
3749 my $range = $array->range('-1:8');
3750  
3751 # [9]
3752  
3753 =back
3754  
3755 =over 4
3756  
3757 =item range example 11
3758  
3759 # given: synopsis
3760  
3761 package main;
3762  
3763 my $range = $array->range('0:8');
3764  
3765 # [1..9]
3766  
3767 =back
3768  
3769 =over 4
3770  
3771 =item range example 12
3772  
3773 # given: synopsis
3774  
3775 package main;
3776  
3777 my $range = $array->range('0:-2');
3778  
3779 # [1..8]
3780  
3781 =back
3782  
3783 =over 4
3784  
3785 =item range example 13
3786  
3787 # given: synopsis
3788  
3789 package main;
3790  
3791 my $range = $array->range('-2:-2');
3792  
3793 # [8]
3794  
3795 =back
3796  
3797 =over 4
3798  
3799 =item range example 14
3800  
3801 # given: synopsis
3802  
3803 package main;
3804  
3805 my $range = $array->range('0:-20');
3806  
3807 # []
3808  
3809 =back
3810  
3811 =over 4
3812  
3813 =item range example 15
3814  
3815 # given: synopsis
3816  
3817 package main;
3818  
3819 my $range = $array->range('-2:-20');
3820  
3821 # []
3822  
3823 =back
3824  
3825 =over 4
3826  
3827 =item range example 16
3828  
3829 # given: synopsis
3830  
3831 package main;
3832  
3833 my $range = $array->range('-2:-6');
3834  
3835 # []
3836  
3837 =back
3838  
3839 =over 4
3840  
3841 =item range example 17
3842  
3843 # given: synopsis
3844  
3845 package main;
3846  
3847 my $range = $array->range('-2:-8');
3848  
3849 # []
3850  
3851 =back
3852  
3853 =over 4
3854  
3855 =item range example 18
3856  
3857 # given: synopsis
3858  
3859 package main;
3860  
3861 my $range = $array->range('-2:-9');
3862  
3863 # []
3864  
3865 =back
3866  
3867 =over 4
3868  
3869 =item range example 19
3870  
3871 # given: synopsis
3872  
3873 package main;
3874  
3875 my $range = $array->range('-5:-1');
3876  
3877 # [5..9]
3878  
3879 =back
3880  
3881 =cut
3882  
3883 =head2 reverse
3884  
3885 reverse() (arrayref)
3886  
3887 The reverse method returns an array reference containing the elements in the
3888 array in reverse order.
3889  
3890 I<Since C<0.01>>
3891  
3892 =over 4
3893  
3894 =item reverse example 1
3895  
3896 # given: synopsis;
3897  
3898 my $reverse = $array->reverse;
3899  
3900 # [9, 8, 7, 6, 5, 4, 3, 2, 1]
3901  
3902 =back
3903  
3904 =cut
3905  
3906 =head2 rotate
3907  
3908 rotate() (arrayref)
3909  
3910 The rotate method rotates the elements in the array such that first elements
3911 becomes the last element and the second element becomes the first element each
3912 time this method is called.
3913  
3914 I<Since C<0.01>>
3915  
3916 =over 4
3917  
3918 =item rotate example 1
3919  
3920 # given: synopsis;
3921  
3922 my $rotate = $array->rotate;
3923  
3924 # [2..9, 1]
3925  
3926 =back
3927  
3928 =cut
3929  
3930 =head2 rsort
3931  
3932 rsort() (arrayref)
3933  
3934 The rsort method returns an array reference containing the values in the array
3935 sorted alphanumerically in reverse.
3936  
3937 I<Since C<0.01>>
3938  
3939 =over 4
3940  
3941 =item rsort example 1
3942  
3943 # given: synopsis;
3944  
3945 my $rsort = $array->rsort;
3946  
3947 # [9, 8, 7, 6, 5, 4, 3, 2, 1]
3948  
3949 =back
3950  
3951 =cut
3952  
3953 =head2 sets
3954  
3955 sets(string @args) (arrayref)
3956  
3957 The sets method find values from within the underlying data structure using
3958 L<Venus::Array/path>, where each argument pair is a selector and value, and
3959 returns all the values provided. Returns a list in list context. Note, nested
3960 data structures can be updated but not created.
3961  
3962 I<Since C<4.15>>
3963  
3964 =over 4
3965  
3966 =item sets example 1
3967  
3968 package main;
3969  
3970 use Venus::Array;
3971  
3972 my $array = Venus::Array->new(['foo', {'bar' => 'baz'}, 'bar', ['baz']]);
3973  
3974 my $sets = $array->sets('3' => 'bar', '1.bar' => 'bar');
3975  
3976 # ['bar', 'bar']
3977  
3978 =back
3979  
3980 =over 4
3981  
3982 =item sets example 2
3983  
3984 package main;
3985  
3986 use Venus::Array;
3987  
3988 my $array = Venus::Array->new(['foo', {'bar' => 'baz'}, 'bar', ['baz']]);
3989  
3990 my ($baz, $one_bar) = $array->sets('3' => 'bar', '1.bar' => 'bar');
3991  
3992 # ('bar', 'bar')
3993  
3994 =back
3995  
3996 =over 4
3997  
3998 =item sets example 3
3999  
4000 package main;
4001  
4002 use Venus::Array;
4003  
4004 my $array = Venus::Array->new(['foo', {'bar' => 'baz'}, 'bar', ['baz']]);
4005  
4006 my $sets = $array->sets('3' => 'bar', '1.bar' => 'bar', '1.baz' => 'box');
4007  
4008 # ['bar', 'bar', 'box']
4009  
4010 =back
4011  
4012 =over 4
4013  
4014 =item sets example 4
4015  
4016 package main;
4017  
4018 use Venus::Array;
4019  
4020 my $array = Venus::Array->new(['foo', {'bar' => 'baz'}, 'bar', ['baz']]);
4021  
4022 my $sets = $array->sets('3' => 'bar', '1.bar' => 'bar', '1.bar.baz' => 'box');
4023  
4024 # ['bar', 'bar', 'box']
4025  
4026 =back
4027  
4028 =cut
4029  
4030 =head2 shift
4031  
4032 shift() (any)
4033  
4034 The shift method returns the first element of the array shortening it by one.
4035  
4036 I<Since C<0.01>>
4037  
4038 =over 4
4039  
4040 =item shift example 1
4041  
4042 # given: synopsis;
4043  
4044 my $shift = $array->shift;
4045  
4046 # 1
4047  
4048 =back
4049  
4050 =cut
4051  
4052 =head2 shuffle
4053  
4054 shuffle() (arrayref)
4055  
4056 The shuffle method returns an array with the items in a randomized order.
4057  
4058 I<Since C<1.40>>
4059  
4060 =over 4
4061  
4062 =item shuffle example 1
4063  
4064 # given: synopsis
4065  
4066 package main;
4067  
4068 my $shuffle = $array->shuffle;
4069  
4070 # [4, 5, 8, 7, 2, 9, 6, 3, 1]
4071  
4072 =back
4073  
4074 =cut
4075  
4076 =head2 slice
4077  
4078 slice(string @keys) (arrayref)
4079  
4080 The slice method returns a hash reference containing the elements in the array
4081 at the index(es) specified in the arguments.
4082  
4083 I<Since C<0.01>>
4084  
4085 =over 4
4086  
4087 =item slice example 1
4088  
4089 # given: synopsis;
4090  
4091 my $slice = $array->slice(2, 4);
4092  
4093 # [3, 5]
4094  
4095 =back
4096  
4097 =cut
4098  
4099 =head2 sort
4100  
4101 sort() (arrayref)
4102  
4103 The sort method returns an array reference containing the values in the array
4104 sorted alphanumerically.
4105  
4106 I<Since C<0.01>>
4107  
4108 =over 4
4109  
4110 =item sort example 1
4111  
4112 package main;
4113  
4114 use Venus::Array;
4115  
4116 my $array = Venus::Array->new(['d','c','b','a']);
4117  
4118 my $sort = $array->sort;
4119  
4120 # ["a".."d"]
4121  
4122 =back
4123  
4124 =cut
4125  
4126 =head2 tail
4127  
4128 tail(number $size) (arrayref)
4129  
4130 The tail method returns the bottommost elements, limited by the desired size
4131 specified.
4132  
4133 I<Since C<1.23>>
4134  
4135 =over 4
4136  
4137 =item tail example 1
4138  
4139 # given: synopsis;
4140  
4141 my $tail = $array->tail;
4142  
4143 # [9]
4144  
4145 =back
4146  
4147 =over 4
4148  
4149 =item tail example 2
4150  
4151 # given: synopsis;
4152  
4153 my $tail = $array->tail(1);
4154  
4155 # [9]
4156  
4157 =back
4158  
4159 =over 4
4160  
4161 =item tail example 3
4162  
4163 # given: synopsis;
4164  
4165 my $tail = $array->tail(2);
4166  
4167 # [8,9]
4168  
4169 =back
4170  
4171 =over 4
4172  
4173 =item tail example 4
4174  
4175 # given: synopsis;
4176  
4177 my $tail = $array->tail(5);
4178  
4179 # [5..9]
4180  
4181 =back
4182  
4183 =over 4
4184  
4185 =item tail example 5
4186  
4187 # given: synopsis;
4188  
4189 my $tail = $array->tail(20);
4190  
4191 # [1..9]
4192  
4193 =back
4194  
4195 =cut
4196  
4197 =head2 tv
4198  
4199 tv(any $arg) (boolean)
4200  
4201 The tv method performs a I<"type-and-value-equal-to"> operation using argument
4202 provided.
4203  
4204 I<Since C<0.08>>
4205  
4206 =over 4
4207  
4208 =item tv example 1
4209  
4210 package main;
4211  
4212 use Venus::Array;
4213  
4214 my $lvalue = Venus::Array->new;
4215 my $rvalue = Venus::Array->new;
4216  
4217 my $result = $lvalue->tv($rvalue);
4218  
4219 # 1
4220  
4221 =back
4222  
4223 =over 4
4224  
4225 =item tv example 2
4226  
4227 package main;
4228  
4229 use Venus::Array;
4230 use Venus::Code;
4231  
4232 my $lvalue = Venus::Array->new;
4233 my $rvalue = Venus::Code->new;
4234  
4235 my $result = $lvalue->tv($rvalue);
4236  
4237 # 0
4238  
4239 =back
4240  
4241 =over 4
4242  
4243 =item tv example 3
4244  
4245 package main;
4246  
4247 use Venus::Array;
4248 use Venus::Float;
4249  
4250 my $lvalue = Venus::Array->new;
4251 my $rvalue = Venus::Float->new;
4252  
4253 my $result = $lvalue->tv($rvalue);
4254  
4255 # 0
4256  
4257 =back
4258  
4259 =over 4
4260  
4261 =item tv example 4
4262  
4263 package main;
4264  
4265 use Venus::Array;
4266 use Venus::Hash;
4267  
4268 my $lvalue = Venus::Array->new;
4269 my $rvalue = Venus::Hash->new;
4270  
4271 my $result = $lvalue->tv($rvalue);
4272  
4273 # 0
4274  
4275 =back
4276  
4277 =over 4
4278  
4279 =item tv example 5
4280  
4281 package main;
4282  
4283 use Venus::Array;
4284 use Venus::Number;
4285  
4286 my $lvalue = Venus::Array->new;
4287 my $rvalue = Venus::Number->new;
4288  
4289 my $result = $lvalue->tv($rvalue);
4290  
4291 # 0
4292  
4293 =back
4294  
4295 =over 4
4296  
4297 =item tv example 6
4298  
4299 package main;
4300  
4301 use Venus::Array;
4302 use Venus::Regexp;
4303  
4304 my $lvalue = Venus::Array->new;
4305 my $rvalue = Venus::Regexp->new;
4306  
4307 my $result = $lvalue->tv($rvalue);
4308  
4309 # 0
4310  
4311 =back
4312  
4313 =over 4
4314  
4315 =item tv example 7
4316  
4317 package main;
4318  
4319 use Venus::Array;
4320 use Venus::Scalar;
4321  
4322 my $lvalue = Venus::Array->new;
4323 my $rvalue = Venus::Scalar->new;
4324  
4325 my $result = $lvalue->tv($rvalue);
4326  
4327 # 0
4328  
4329 =back
4330  
4331 =over 4
4332  
4333 =item tv example 8
4334  
4335 package main;
4336  
4337 use Venus::Array;
4338 use Venus::String;
4339  
4340 my $lvalue = Venus::Array->new;
4341 my $rvalue = Venus::String->new;
4342  
4343 my $result = $lvalue->tv($rvalue);
4344  
4345 # 0
4346  
4347 =back
4348  
4349 =over 4
4350  
4351 =item tv example 9
4352  
4353 package main;
4354  
4355 use Venus::Array;
4356 use Venus::Undef;
4357  
4358 my $lvalue = Venus::Array->new;
4359 my $rvalue = Venus::Undef->new;
4360  
4361 my $result = $lvalue->tv($rvalue);
4362  
4363 # 0
4364  
4365 =back
4366  
4367 =cut
4368  
4369 =head2 unique
4370  
4371 unique() (arrayref)
4372  
4373 The unique method returns an array reference consisting of the unique elements
4374 in the array.
4375  
4376 I<Since C<0.01>>
4377  
4378 =over 4
4379  
4380 =item unique example 1
4381  
4382 package main;
4383  
4384 use Venus::Array;
4385  
4386 my $array = Venus::Array->new([1,1,1,1,2,3,1]);
4387  
4388 my $unique = $array->unique;
4389  
4390 # [1, 2, 3]
4391  
4392 =back
4393  
4394 =cut
4395  
4396 =head2 unshift
4397  
4398 unshift(any @data) (arrayref)
4399  
4400 The unshift method prepends the array by pushing the agruments onto it and
4401 returns itself.
4402  
4403 I<Since C<0.01>>
4404  
4405 =over 4
4406  
4407 =item unshift example 1
4408  
4409 # given: synopsis;
4410  
4411 my $unshift = $array->unshift(-2,-1,0);
4412  
4413 # [-2..9]
4414  
4415 =back
4416  
4417 =cut
4418  
4419 =head1 AUTHORS
4420  
4421 Awncorp, C<awncorp@cpan.org>
4422  
4423 =cut
4424  
4425 =head1 LICENSE
4426  
4427 Copyright (C) 2022, Awncorp, C<awncorp@cpan.org>.
4428  
4429 This program is free software, you can redistribute it and/or modify it under
4430 the terms of the Apache license version 2.0.
4431  
4432 =cut
« blib/lib/Venus/Random.pm ↑ Summary blib/lib/Venus/Yaml.pm »