File Coverage

blib/lib/Hydrogen/Topic/ArrayRef.pm
Criterion Covered Total %
statement 181 489 37.0
branch 60 296 20.2
condition 18 81 22.2
subroutine 35 84 41.6
pod 62 62 100.0
total 356 1012 35.1


line stmt bran cond sub pod time code
1             # This file was autogenerated.
2 2     2   223282 use 5.008001;
  2         9  
3 2     2   13 use strict;
  2         3  
  2         64  
4 2     2   11 use warnings;
  2         3  
  2         122  
5 2     2   11 no warnings qw( void once );
  2         4  
  2         97  
6 2     2   538 use Hydrogen ();
  2         18  
  2         283  
7              
8             package Hydrogen::Topic::ArrayRef;
9              
10             our $AUTHORITY = 'cpan:TOBYINK';
11             our $VERSION = '0.021001';
12              
13             =head1 NAME
14              
15             Hydrogen::Topic::ArrayRef - functions from Hydrogen::ArrayRef applied to C<$_>
16              
17             =head1 VERSION
18              
19             This documentation is for Hydrogen::Topic::ArrayRef 0.021001,
20             which is based on Sub::HandlesVia::HandlerLibrary::Array 0.050005.
21              
22             =cut
23              
24             =head1 FUNCTIONS
25              
26             Each function implicitly operates on C<< $_ >>, expecting it to be a reference to an array.
27              
28             =cut
29              
30 2         28 use Exporter::Shiny qw(
31             accessor
32             all
33             all_true
34             any
35             apply
36             clear
37             count
38             delete
39             elements
40             first
41             first_index
42             flatten
43             flatten_deep
44             for_each
45             for_each_pair
46             get
47             grep
48             head
49             indexed
50             insert
51             is_empty
52             join
53             map
54             max
55             maxstr
56             min
57             minstr
58             natatime
59             not_all_true
60             pairfirst
61             pairgrep
62             pairkeys
63             pairmap
64             pairs
65             pairvalues
66             pick_random
67             pop
68             print
69             product
70             push
71             reduce
72             reductions
73             reset
74             reverse
75             sample
76             set
77             shallow_clone
78             shift
79             shuffle
80             shuffle_in_place
81             sort
82             sort_in_place
83             splice
84             sum
85             tail
86             uniq
87             uniq_in_place
88             uniqnum
89             uniqnum_in_place
90             uniqstr
91             uniqstr_in_place
92             unshift
93 2     2   15 );
  2         8  
94              
95             =head2 C<< accessor( $index, $value? ) >>
96              
97             Operates on C<< $_ >>, which must be a reference to an array.
98              
99             Arguments: B<< Int >>, B<< Optional[Any] >>.
100              
101             Acts like C if given just an index, or C if given an index and value.
102              
103             =cut
104              
105             {
106             my $__signature;
107              
108             sub accessor {
109              
110             package Hydrogen::ArrayRef::__SANDBOX__;
111             $__signature ||= sub {
112 2     2   6 my ( %tmp, $tmp );
113              
114 2 50 33     32 @_ >= 1 && @_ <= 2
115             or Hydrogen::croak(
116             "Wrong number of parameters in signature for %s: got %d, %s",
117             "accessor", scalar(@_), "expected exactly 1 parameters" );
118              
119             # Parameter $_[0] (type: Int)
120             (
121 2 50       4 do {
122 2         6 my $tmp = $_[0];
123 2 50 33     36 defined($tmp) and !ref($tmp) and $tmp =~ /\A-?[0-9]+\z/;
124             }
125             )
126             or Hydrogen::croak(
127             "Type check failed in signature for accessor: %s should be %s",
128             "\$_[0]", "Int"
129             );
130              
131             # Parameter $_[1] (type: Optional[Any])
132 2 100       10 $#_ >= 1
133             or return (@_);
134 1         2 ( !!1 )
135             or Hydrogen::croak(
136             "Type check failed in signature for accessor: %s should be %s",
137             "\$_[1]", "Optional[Any]"
138             );
139              
140 1         6 (@_);
141 2   66 2 1 345573 };
142 2         6 @_ = &$__signature;
143 2         4 1;
144 2 100       16 ( ( 0 + @_ ) == 1 ) ? ($_)->[ $_[0] ] : ( ($_)->[ $_[0] ] = $_[1] );
145             }
146             }
147              
148             =head2 C<< all() >>
149              
150             Operates on C<< $_ >>, which must be a reference to an array.
151              
152             All elements in the array, in list context.
153              
154             =cut
155              
156             sub all {
157              
158             package Hydrogen::ArrayRef::__SANDBOX__;
159 1 50   1 1 8361 @_ == 0
160             or Hydrogen::croak( "Wrong number of parameters for all; usage: "
161             . "Hydrogen::Topic::ArrayRef::all()" );
162 1         3 @{$_};
  1         6  
163             }
164              
165             =head2 C<< all_true( $coderef ) >>
166              
167             Operates on C<< $_ >>, which must be a reference to an array.
168              
169             Arguments: B<< CodeRef >>.
170              
171             Like C<< List::Util::all() >>.
172              
173             =cut
174              
175             sub all_true {
176              
177             package Hydrogen::ArrayRef::__SANDBOX__;
178 0     0 1 0 @_ = do {
179 0         0 my ( %tmp, $tmp );
180              
181 0 0       0 @_ == 1
182             or Hydrogen::croak(
183             "Wrong number of parameters in signature for %s: got %d, %s",
184             "all_true", scalar(@_), "expected exactly 1 parameters" );
185              
186             # Parameter $_[0] (type: CodeRef)
187 0 0       0 ( ref( $_[0] ) eq 'CODE' )
188             or Hydrogen::croak(
189             "Type check failed in signature for all_true: %s should be %s",
190             "\$_[0]", "CodeRef" );
191              
192 0         0 (@_);
193             };
194 0         0 &List::Util::all( $_[0], @{$_} );
  0         0  
195             }
196              
197             =head2 C<< any( $coderef ) >>
198              
199             Operates on C<< $_ >>, which must be a reference to an array.
200              
201             Arguments: B<< CodeRef >>.
202              
203             Like C<< List::Util::any() >>.
204              
205             =cut
206              
207             sub any {
208              
209             package Hydrogen::ArrayRef::__SANDBOX__;
210 1     1 1 9536 @_ = do {
211 1         4 my ( %tmp, $tmp );
212              
213 1 50       6 @_ == 1
214             or Hydrogen::croak(
215             "Wrong number of parameters in signature for %s: got %d, %s",
216             "any", scalar(@_), "expected exactly 1 parameters" );
217              
218             # Parameter $_[0] (type: CodeRef)
219 1 50       5 ( ref( $_[0] ) eq 'CODE' )
220             or Hydrogen::croak(
221             "Type check failed in signature for any: %s should be %s",
222             "\$_[0]", "CodeRef" );
223              
224 1         5 (@_);
225             };
226 1         37 &List::Util::any( $_[0], @{$_} );
  1         8  
227             }
228              
229             =head2 C<< apply( $coderef ) >>
230              
231             Operates on C<< $_ >>, which must be a reference to an array.
232              
233             Arguments: B<< CodeRef >>.
234              
235             Executes the coderef (which should modify C<< $_ >>) against each element of the array; returns the resulting array in list context.
236              
237             =cut
238              
239             sub apply {
240              
241             package Hydrogen::ArrayRef::__SANDBOX__;
242 0     0 1 0 @_ = do {
243 0         0 my ( %tmp, $tmp );
244              
245 0 0       0 @_ == 1
246             or Hydrogen::croak(
247             "Wrong number of parameters in signature for %s: got %d, %s",
248             "apply", scalar(@_), "expected exactly 1 parameters" );
249              
250             # Parameter $_[0] (type: CodeRef)
251 0 0       0 ( ref( $_[0] ) eq 'CODE' )
252             or Hydrogen::croak(
253             "Type check failed in signature for apply: %s should be %s",
254             "\$_[0]", "CodeRef" );
255              
256 0         0 (@_);
257             };
258 0         0 my @shv_tmp = @{$_};
  0         0  
259 0         0 &{ $_[0] } foreach @shv_tmp;
  0         0  
260 0 0       0 wantarray ? @shv_tmp : $shv_tmp[-1];
261             }
262              
263             =head2 C<< clear() >>
264              
265             Operates on C<< $_ >>, which must be a reference to an array.
266              
267             Empties the array.
268              
269             =cut
270              
271             sub clear {
272              
273             package Hydrogen::ArrayRef::__SANDBOX__;
274 1 50   1 1 11750 @_ == 0
275             or Hydrogen::croak( "Wrong number of parameters for clear; usage: "
276             . "Hydrogen::Topic::ArrayRef::clear()" );
277 1         2 1;
278 1         3 @{$_} = ();
  1         5  
279             }
280              
281             =head2 C<< count() >>
282              
283             Operates on C<< $_ >>, which must be a reference to an array.
284              
285             The number of elements in the referenced array.
286              
287             =cut
288              
289             sub count {
290              
291             package Hydrogen::ArrayRef::__SANDBOX__;
292 1 50   1 1 9020 @_ == 0
293             or Hydrogen::croak( "Wrong number of parameters for count; usage: "
294             . "Hydrogen::Topic::ArrayRef::count()" );
295 1         3 scalar( @{$_} );
  1         7  
296             }
297              
298             =head2 C<< delete( $index ) >>
299              
300             Operates on C<< $_ >>, which must be a reference to an array.
301              
302             Arguments: B<< Int >>.
303              
304             Removes the indexed element from the array and returns it. Elements after it will be "moved up".
305              
306             =cut
307              
308             sub delete {
309              
310             package Hydrogen::ArrayRef::__SANDBOX__;
311 0     0 1 0 @_ = do {
312 0         0 my ( %tmp, $tmp );
313              
314 0 0       0 @_ == 1
315             or Hydrogen::croak(
316             "Wrong number of parameters in signature for %s: got %d, %s",
317             "delete", scalar(@_), "expected exactly 1 parameters" );
318              
319             # Parameter $_[0] (type: Int)
320             (
321 0 0       0 do {
322 0         0 my $tmp = $_[0];
323 0 0 0     0 defined($tmp) and !ref($tmp) and $tmp =~ /\A-?[0-9]+\z/;
324             }
325             )
326             or Hydrogen::croak(
327             "Type check failed in signature for delete: %s should be %s",
328             "\$_[0]", "Int" );
329              
330 0         0 (@_);
331             };
332 0         0 1;
333 0         0 splice( @{$_}, $_[0], 1 );
  0         0  
334             }
335              
336             =head2 C<< elements() >>
337              
338             Operates on C<< $_ >>, which must be a reference to an array.
339              
340             All elements in the array, in list context. (Essentially the same as C.)
341              
342             =cut
343              
344             sub elements {
345              
346             package Hydrogen::ArrayRef::__SANDBOX__;
347 1 50   1 1 14645 @_ == 0
348             or Hydrogen::croak( "Wrong number of parameters for elements; usage: "
349             . "Hydrogen::Topic::ArrayRef::elements()" );
350 1         3 @{$_};
  1         4  
351             }
352              
353             =head2 C<< first( $coderef ) >>
354              
355             Operates on C<< $_ >>, which must be a reference to an array.
356              
357             Arguments: B<< CodeRef >>.
358              
359             Like C<< List::Util::first() >>.
360              
361             =cut
362              
363             sub first {
364              
365             package Hydrogen::ArrayRef::__SANDBOX__;
366 1     1 1 10174 @_ = do {
367 1         3 my ( %tmp, $tmp );
368              
369 1 50       6 @_ == 1
370             or Hydrogen::croak(
371             "Wrong number of parameters in signature for %s: got %d, %s",
372             "first", scalar(@_), "expected exactly 1 parameters" );
373              
374             # Parameter $_[0] (type: CodeRef)
375 1 50       6 ( ref( $_[0] ) eq 'CODE' )
376             or Hydrogen::croak(
377             "Type check failed in signature for first: %s should be %s",
378             "\$_[0]", "CodeRef" );
379              
380 1         4 (@_);
381             };
382 1         3 &List::Util::first( $_[0], @{$_} );
  1         7  
383             }
384              
385             =head2 C<< first_index( $coderef ) >>
386              
387             Operates on C<< $_ >>, which must be a reference to an array.
388              
389             Arguments: B<< CodeRef >>.
390              
391             Like C<< List::MoreUtils::first_index() >>.
392              
393             =cut
394              
395             sub first_index {
396              
397             package Hydrogen::ArrayRef::__SANDBOX__;
398 1     1 1 3986 @_ = do {
399 1         4 my ( %tmp, $tmp );
400              
401 1 50       5 @_ == 1
402             or Hydrogen::croak(
403             "Wrong number of parameters in signature for %s: got %d, %s",
404             "first_index", scalar(@_), "expected exactly 1 parameters" );
405              
406             # Parameter $_[0] (type: CodeRef)
407 1 50       6 ( ref( $_[0] ) eq 'CODE' )
408             or Hydrogen::croak(
409             "Type check failed in signature for first_index: %s should be %s",
410             "\$_[0]", "CodeRef" );
411              
412 1         4 (@_);
413             };
414 1 100       3 for my $i ( 0 .. $#{$_} ) { local *_ = \$_->[$i]; return $i if $_[0]->($_) };
  1         5  
  3         17  
  3         8  
415 0         0 return -1;
416             }
417              
418             =head2 C<< flatten() >>
419              
420             Operates on C<< $_ >>, which must be a reference to an array.
421              
422             All elements in the array, in list context. (Essentially the same as C.)
423              
424             =cut
425              
426             sub flatten {
427              
428             package Hydrogen::ArrayRef::__SANDBOX__;
429 1 50   1 1 10827 @_ == 0
430             or Hydrogen::croak( "Wrong number of parameters for flatten; usage: "
431             . "Hydrogen::Topic::ArrayRef::flatten()" );
432 1         4 @{$_};
  1         4  
433             }
434              
435             =head2 C<< flatten_deep( $depth? ) >>
436              
437             Operates on C<< $_ >>, which must be a reference to an array.
438              
439             Arguments: B<< Optional[Int] >>.
440              
441             Flattens the arrayref into a list, including any nested arrayrefs. (Has the potential to loop infinitely.)
442              
443             =cut
444              
445             {
446             my $__signature;
447              
448             sub flatten_deep {
449              
450             package Hydrogen::ArrayRef::__SANDBOX__;
451             $__signature ||= sub {
452 2     2   5 my ( %tmp, $tmp );
453              
454 2 50       11 @_ >= 0
455             or Hydrogen::croak(
456             "Wrong number of parameters in signature for %s: got %d, %s",
457             "flatten_deep", scalar(@_), "expected exactly 0 parameters" );
458              
459             # Parameter $_[0] (type: Optional[Int])
460 2 100       8 $#_ >= 0
461             or return (@_);
462             (
463 1 50       41 do {
464 1         4 my $tmp = $_[0];
465 1 50 33     20 defined($tmp) and !ref($tmp) and $tmp =~ /\A-?[0-9]+\z/;
466             }
467             )
468             or Hydrogen::croak(
469             "Type check failed in signature for flatten_deep: %s should be %s",
470             "\$_[0]", "Optional[Int]"
471             );
472              
473 1         5 (@_);
474 2   66 2 1 8166 };
475 2         6 @_ = &$__signature;
476 2         4 my $shv_fd;
477             $shv_fd = sub {
478 5     5   10 my $d = pop;
479 5 100       14 --$d if defined $d;
480 5 100 100     55 map ref() eq "ARRAY"
    100          
481             ? ( defined $d && $d < 0 )
482             ? $_
483             : $shv_fd->( @$_, $d )
484             : $_, @_;
485 2         10 };
486 2         4 $shv_fd->( @{$_}, $_[0] );
  2         10  
487             }
488             }
489              
490             =head2 C<< for_each( $coderef ) >>
491              
492             Operates on C<< $_ >>, which must be a reference to an array.
493              
494             Arguments: B<< CodeRef >>.
495              
496             Function which executes the coderef on each element of the array. The coderef will be passed two values: the element and its index. The element will also be available as C<< $_ >>.
497              
498             =cut
499              
500             sub for_each {
501              
502             package Hydrogen::ArrayRef::__SANDBOX__;
503 1     1 1 6791 @_ = do {
504 1         3 my ( %tmp, $tmp );
505              
506 1 50       6 @_ == 1
507             or Hydrogen::croak(
508             "Wrong number of parameters in signature for %s: got %d, %s",
509             "for_each", scalar(@_), "expected exactly 1 parameters" );
510              
511             # Parameter $_[0] (type: CodeRef)
512 1 50       5 ( ref( $_[0] ) eq 'CODE' )
513             or Hydrogen::croak(
514             "Type check failed in signature for for_each: %s should be %s",
515             "\$_[0]", "CodeRef" );
516              
517 1         5 (@_);
518             };
519 1         2 my $shv_tmp = $_;
520             {
521 1         3 local $_;
  1         3  
522 1         2 foreach my $shv_index ( 0 .. $#{$shv_tmp} ) {
  1         5  
523 3         1552 &{ $_[0] }( $_ = $shv_tmp->[$shv_index], $shv_index );
  3         10  
524             }
525             }
526 1         539 $_;
527             }
528              
529             =head2 C<< for_each_pair( $coderef ) >>
530              
531             Operates on C<< $_ >>, which must be a reference to an array.
532              
533             Arguments: B<< CodeRef >>.
534              
535             Function which executes the coderef on each pair of elements in the array. The coderef will be passed the two elements.
536              
537             =cut
538              
539             sub for_each_pair {
540              
541             package Hydrogen::ArrayRef::__SANDBOX__;
542 0     0 1 0 @_ = do {
543 0         0 my ( %tmp, $tmp );
544              
545 0 0       0 @_ == 1
546             or Hydrogen::croak(
547             "Wrong number of parameters in signature for %s: got %d, %s",
548             "for_each_pair", scalar(@_), "expected exactly 1 parameters" );
549              
550             # Parameter $_[0] (type: CodeRef)
551 0 0       0 ( ref( $_[0] ) eq 'CODE' )
552             or Hydrogen::croak(
553             "Type check failed in signature for for_each_pair: %s should be %s",
554             "\$_[0]", "CodeRef"
555             );
556              
557 0         0 (@_);
558             };
559 0         0 for ( my $shv_index = 0 ; $shv_index < @{$_} ; $shv_index += 2 ) {
  0         0  
560 0         0 &{ $_[0] }( ($_)->[$shv_index], ($_)->[ $shv_index + 1 ] );
  0         0  
561             };
562 0         0 $_;
563             }
564              
565             =head2 C<< get( $index ) >>
566              
567             Operates on C<< $_ >>, which must be a reference to an array.
568              
569             Arguments: B<< Int >>.
570              
571             Returns a single element from the array by index.
572              
573             =cut
574              
575             sub get {
576              
577             package Hydrogen::ArrayRef::__SANDBOX__;
578 3     3 1 9737 @_ = do {
579 3         8 my ( %tmp, $tmp );
580              
581 3 50       13 @_ == 1
582             or Hydrogen::croak(
583             "Wrong number of parameters in signature for %s: got %d, %s",
584             "get", scalar(@_), "expected exactly 1 parameters" );
585              
586             # Parameter $_[0] (type: Int)
587             (
588 3 50       7 do {
589 3         6 my $tmp = $_[0];
590 3 50 33     39 defined($tmp) and !ref($tmp) and $tmp =~ /\A-?[0-9]+\z/;
591             }
592             )
593             or Hydrogen::croak(
594             "Type check failed in signature for get: %s should be %s",
595             "\$_[0]", "Int" );
596              
597 3         13 (@_);
598             };
599 3         24 ($_)->[ $_[0] ];
600             }
601              
602             =head2 C<< grep( $coderef ) >>
603              
604             Operates on C<< $_ >>, which must be a reference to an array.
605              
606             Arguments: B<< CodeRef >>.
607              
608             Like C from L.
609              
610             =cut
611              
612             sub grep {
613              
614             package Hydrogen::ArrayRef::__SANDBOX__;
615 0     0 1 0 @_ = do {
616 0         0 my ( %tmp, $tmp );
617              
618 0 0       0 @_ == 1
619             or Hydrogen::croak(
620             "Wrong number of parameters in signature for %s: got %d, %s",
621             "grep", scalar(@_), "expected exactly 1 parameters" );
622              
623             # Parameter $_[0] (type: CodeRef)
624 0 0       0 ( ref( $_[0] ) eq 'CODE' )
625             or Hydrogen::croak(
626             "Type check failed in signature for grep: %s should be %s",
627             "\$_[0]", "CodeRef" );
628              
629 0         0 (@_);
630             };
631 0         0 grep( $_[0]->($_), @{$_} );
  0         0  
632             }
633              
634             =head2 C<< head( $count ) >>
635              
636             Operates on C<< $_ >>, which must be a reference to an array.
637              
638             Arguments: B<< Int >>.
639              
640             Returns the first C<< $count >> elements of the array in list context.
641              
642             =cut
643              
644             sub head {
645              
646             package Hydrogen::ArrayRef::__SANDBOX__;
647 0     0 1 0 @_ = do {
648 0         0 my ( %tmp, $tmp );
649              
650 0 0       0 @_ == 1
651             or Hydrogen::croak(
652             "Wrong number of parameters in signature for %s: got %d, %s",
653             "head", scalar(@_), "expected exactly 1 parameters" );
654              
655             # Parameter $_[0] (type: Int)
656             (
657 0 0       0 do {
658 0         0 my $tmp = $_[0];
659 0 0 0     0 defined($tmp) and !ref($tmp) and $tmp =~ /\A-?[0-9]+\z/;
660             }
661             )
662             or Hydrogen::croak(
663             "Type check failed in signature for head: %s should be %s",
664             "\$_[0]", "Int" );
665              
666 0         0 (@_);
667             };
668 0         0 my $shv_count = $_[0];
669 0 0       0 $shv_count = @{$_} if $shv_count > @{$_};
  0         0  
  0         0  
670 0 0       0 $shv_count = @{$_} + $shv_count if $shv_count < 0;
  0         0  
671 0         0 ( @{$_} )[ 0 .. ( $shv_count - 1 ) ];
  0         0  
672             }
673              
674             =head2 C<< indexed() >>
675              
676             Operates on C<< $_ >>, which must be a reference to an array.
677              
678             Like C from L.
679              
680             =cut
681              
682             sub indexed {
683              
684             package Hydrogen::ArrayRef::__SANDBOX__;
685 0 0   0 1 0 @_ == 0
686             or Hydrogen::croak( "Wrong number of parameters for indexed; usage: "
687             . "Hydrogen::Topic::ArrayRef::indexed()" );
688 0         0 my $shv_ix = 0;
689 0         0 map +( $shv_ix++, $_ ), @{$_};
  0         0  
690             }
691              
692             =head2 C<< insert( $index, $value ) >>
693              
694             Operates on C<< $_ >>, which must be a reference to an array.
695              
696             Arguments: B<< Int >>, B<< Any >>.
697              
698             Inserts a value into the array with the given index. Elements after it will be "moved down".
699              
700             =cut
701              
702             sub insert {
703              
704             package Hydrogen::ArrayRef::__SANDBOX__;
705 1     1 1 24675 @_ = do {
706 1         3 my ( %tmp, $tmp );
707              
708 1 50       6 @_ == 2
709             or Hydrogen::croak(
710             "Wrong number of parameters in signature for %s: got %d, %s",
711             "insert", scalar(@_), "expected exactly 2 parameters" );
712              
713             # Parameter $_[0] (type: Int)
714             (
715 1 50       2 do {
716 1         3 my $tmp = $_[0];
717 1 50 33     22 defined($tmp) and !ref($tmp) and $tmp =~ /\A-?[0-9]+\z/;
718             }
719             )
720             or Hydrogen::croak(
721             "Type check failed in signature for insert: %s should be %s",
722             "\$_[0]", "Int" );
723              
724             # Parameter $_[1] (type: Any)
725 1         3 1; # ... nothing to do
726              
727 1         5 (@_);
728             };
729 1         2 1;
730 1         4 splice( @{$_}, $_[0], 0, $_[1] );
  1         5  
731             }
732              
733             =head2 C<< is_empty() >>
734              
735             Operates on C<< $_ >>, which must be a reference to an array.
736              
737             Boolean indicating if the referenced array is empty.
738              
739             =cut
740              
741             sub is_empty {
742              
743             package Hydrogen::ArrayRef::__SANDBOX__;
744 2 50   2 1 11492 @_ == 0
745             or Hydrogen::croak( "Wrong number of parameters for is_empty; usage: "
746             . "Hydrogen::Topic::ArrayRef::is_empty()" );
747 2         5 !scalar( @{$_} );
  2         9  
748             }
749              
750             =head2 C<< join( $with? ) >>
751              
752             Operates on C<< $_ >>, which must be a reference to an array.
753              
754             Arguments: B<< Optional[Str] >>.
755              
756             Returns a string joining all the elements in the array; if C<< $with >> is omitted, defaults to a comma.
757              
758             =cut
759              
760             {
761             my $__signature;
762              
763             sub join {
764              
765             package Hydrogen::ArrayRef::__SANDBOX__;
766             $__signature ||= sub {
767 2     2   6 my ( %tmp, $tmp );
768              
769 2 50       8 @_ >= 0
770             or Hydrogen::croak(
771             "Wrong number of parameters in signature for %s: got %d, %s",
772             "join", scalar(@_), "expected exactly 0 parameters" );
773              
774             # Parameter $_[0] (type: Optional[Str])
775 2 100       10 $#_ >= 0
776             or return (@_);
777 1 50       2 do {
778              
779             package Hydrogen::ArrayRef::__SANDBOX__;
780 1 50       7 defined( $_[0] ) and do {
781 1 50       16 ref( \$_[0] ) eq 'SCALAR'
782             or ref( \( my $val = $_[0] ) ) eq 'SCALAR';
783             }
784             }
785             or Hydrogen::croak(
786             "Type check failed in signature for join: %s should be %s",
787             "\$_[0]", "Optional[Str]" );
788              
789 1         5 (@_);
790 2   66 2 1 13707 };
791 2         51 @_ = &$__signature;
792 2 100       9 my $shv_param_with = ( 0 + @_ ) ? $_[0] : q[,];
793 2         3 join( $shv_param_with, @{$_} );
  2         18  
794             }
795             }
796              
797             =head2 C<< map( $coderef ) >>
798              
799             Operates on C<< $_ >>, which must be a reference to an array.
800              
801             Arguments: B<< CodeRef >>.
802              
803             Like C from L.
804              
805             =cut
806              
807             sub map {
808              
809             package Hydrogen::ArrayRef::__SANDBOX__;
810 0     0 1 0 @_ = do {
811 0         0 my ( %tmp, $tmp );
812              
813 0 0       0 @_ == 1
814             or Hydrogen::croak(
815             "Wrong number of parameters in signature for %s: got %d, %s",
816             "map", scalar(@_), "expected exactly 1 parameters" );
817              
818             # Parameter $_[0] (type: CodeRef)
819 0 0       0 ( ref( $_[0] ) eq 'CODE' )
820             or Hydrogen::croak(
821             "Type check failed in signature for map: %s should be %s",
822             "\$_[0]", "CodeRef" );
823              
824 0         0 (@_);
825             };
826 0         0 map( $_[0]->($_), @{$_} );
  0         0  
827             }
828              
829             =head2 C<< max() >>
830              
831             Operates on C<< $_ >>, which must be a reference to an array.
832              
833             Like C<< List::Util::max() >>.
834              
835             =cut
836              
837             sub max {
838              
839             package Hydrogen::ArrayRef::__SANDBOX__;
840 0 0   0 1 0 @_ == 0
841             or Hydrogen::croak( "Wrong number of parameters for max; usage: "
842             . "Hydrogen::Topic::ArrayRef::max()" );
843 0         0 &List::Util::max( @{$_} );
  0         0  
844             }
845              
846             =head2 C<< maxstr() >>
847              
848             Operates on C<< $_ >>, which must be a reference to an array.
849              
850             Like C<< List::Util::maxstr() >>.
851              
852             =cut
853              
854             sub maxstr {
855              
856             package Hydrogen::ArrayRef::__SANDBOX__;
857 0 0   0 1 0 @_ == 0
858             or Hydrogen::croak( "Wrong number of parameters for maxstr; usage: "
859             . "Hydrogen::Topic::ArrayRef::maxstr()" );
860 0         0 &List::Util::maxstr( @{$_} );
  0         0  
861             }
862              
863             =head2 C<< min() >>
864              
865             Operates on C<< $_ >>, which must be a reference to an array.
866              
867             Like C<< List::Util::min() >>.
868              
869             =cut
870              
871             sub min {
872              
873             package Hydrogen::ArrayRef::__SANDBOX__;
874 0 0   0 1 0 @_ == 0
875             or Hydrogen::croak( "Wrong number of parameters for min; usage: "
876             . "Hydrogen::Topic::ArrayRef::min()" );
877 0         0 &List::Util::min( @{$_} );
  0         0  
878             }
879              
880             =head2 C<< minstr() >>
881              
882             Operates on C<< $_ >>, which must be a reference to an array.
883              
884             Like C<< List::Util::minstr() >>.
885              
886             =cut
887              
888             sub minstr {
889              
890             package Hydrogen::ArrayRef::__SANDBOX__;
891 0 0   0 1 0 @_ == 0
892             or Hydrogen::croak( "Wrong number of parameters for minstr; usage: "
893             . "Hydrogen::Topic::ArrayRef::minstr()" );
894 0         0 &List::Util::minstr( @{$_} );
  0         0  
895             }
896              
897             =head2 C<< natatime( $n, $callback? ) >>
898              
899             Operates on C<< $_ >>, which must be a reference to an array.
900              
901             Arguments: B<< Int >>, B<< Optional[CodeRef] >>.
902              
903             Given just a number, returns an iterator which reads that many elements from the array at a time. If also given a callback, calls the callback repeatedly with those values.
904              
905             =cut
906              
907             {
908             my $__signature;
909              
910             sub natatime {
911              
912             package Hydrogen::ArrayRef::__SANDBOX__;
913             $__signature ||= sub {
914 1     1   2 my ( %tmp, $tmp );
915              
916 1 50 33     9 @_ >= 1 && @_ <= 2
917             or Hydrogen::croak(
918             "Wrong number of parameters in signature for %s: got %d, %s",
919             "natatime", scalar(@_), "expected exactly 1 parameters" );
920              
921             # Parameter $_[0] (type: Int)
922             (
923 1 50       3 do {
924 1         3 my $tmp = $_[0];
925 1 50 33     16 defined($tmp) and !ref($tmp) and $tmp =~ /\A-?[0-9]+\z/;
926             }
927             )
928             or Hydrogen::croak(
929             "Type check failed in signature for natatime: %s should be %s",
930             "\$_[0]", "Int"
931             );
932              
933             # Parameter $_[1] (type: Optional[CodeRef])
934 1 50       7 $#_ >= 1
935             or return (@_);
936 0 0       0 ( ref( $_[1] ) eq 'CODE' )
937             or Hydrogen::croak(
938             "Type check failed in signature for natatime: %s should be %s",
939             "\$_[1]", "Optional[CodeRef]"
940             );
941              
942 0         0 (@_);
943 1   33 1 1 40840 };
944 1         3 @_ = &$__signature;
945 1         3 my @shv_remaining = @{$_};
  1         4  
946 1         2 my $shv_n = $_[0];
947 1     2   5 my $shv_iterator = sub { CORE::splice @shv_remaining, 0, $shv_n };
  2         19  
948 1 50       5 if ( $_[1] ) {
949 0         0 while ( my @shv_values = $shv_iterator->() ) {
950 0         0 $_[1]->(@shv_values);
951             }
952             }
953 1         5 else { $shv_iterator }
954             }
955             }
956              
957             =head2 C<< not_all_true( $coderef ) >>
958              
959             Operates on C<< $_ >>, which must be a reference to an array.
960              
961             Arguments: B<< CodeRef >>.
962              
963             Like C<< List::Util::notall() >>.
964              
965             =cut
966              
967             sub not_all_true {
968              
969             package Hydrogen::ArrayRef::__SANDBOX__;
970 0     0 1 0 @_ = do {
971 0         0 my ( %tmp, $tmp );
972              
973 0 0       0 @_ == 1
974             or Hydrogen::croak(
975             "Wrong number of parameters in signature for %s: got %d, %s",
976             "not_all_true", scalar(@_), "expected exactly 1 parameters" );
977              
978             # Parameter $_[0] (type: CodeRef)
979 0 0       0 ( ref( $_[0] ) eq 'CODE' )
980             or Hydrogen::croak(
981             "Type check failed in signature for not_all_true: %s should be %s",
982             "\$_[0]", "CodeRef"
983             );
984              
985 0         0 (@_);
986             };
987 0         0 &List::Util::notall( $_[0], @{$_} );
  0         0  
988             }
989              
990             =head2 C<< pairfirst( $coderef ) >>
991              
992             Operates on C<< $_ >>, which must be a reference to an array.
993              
994             Arguments: B<< CodeRef >>.
995              
996             Like C<< List::Util::pairfirst() >>.
997              
998             =cut
999              
1000             sub pairfirst {
1001              
1002             package Hydrogen::ArrayRef::__SANDBOX__;
1003 0     0 1 0 @_ = do {
1004 0         0 my ( %tmp, $tmp );
1005              
1006 0 0       0 @_ == 1
1007             or Hydrogen::croak(
1008             "Wrong number of parameters in signature for %s: got %d, %s",
1009             "pairfirst", scalar(@_), "expected exactly 1 parameters" );
1010              
1011             # Parameter $_[0] (type: CodeRef)
1012 0 0       0 ( ref( $_[0] ) eq 'CODE' )
1013             or Hydrogen::croak(
1014             "Type check failed in signature for pairfirst: %s should be %s",
1015             "\$_[0]", "CodeRef" );
1016              
1017 0         0 (@_);
1018             };
1019 0     0   0 List::Util::pairfirst { $_[0]->($_) } @{$_};
  0         0  
  0         0  
1020             }
1021              
1022             =head2 C<< pairgrep( $coderef ) >>
1023              
1024             Operates on C<< $_ >>, which must be a reference to an array.
1025              
1026             Arguments: B<< CodeRef >>.
1027              
1028             Like C<< List::Util::pairgrep() >>.
1029              
1030             =cut
1031              
1032             sub pairgrep {
1033              
1034             package Hydrogen::ArrayRef::__SANDBOX__;
1035 0     0 1 0 @_ = do {
1036 0         0 my ( %tmp, $tmp );
1037              
1038 0 0       0 @_ == 1
1039             or Hydrogen::croak(
1040             "Wrong number of parameters in signature for %s: got %d, %s",
1041             "pairgrep", scalar(@_), "expected exactly 1 parameters" );
1042              
1043             # Parameter $_[0] (type: CodeRef)
1044 0 0       0 ( ref( $_[0] ) eq 'CODE' )
1045             or Hydrogen::croak(
1046             "Type check failed in signature for pairgrep: %s should be %s",
1047             "\$_[0]", "CodeRef" );
1048              
1049 0         0 (@_);
1050             };
1051 0     0   0 List::Util::pairgrep { $_[0]->($_) } @{$_};
  0         0  
  0         0  
1052             }
1053              
1054             =head2 C<< pairkeys() >>
1055              
1056             Operates on C<< $_ >>, which must be a reference to an array.
1057              
1058             Like C<< List::Util::pairkeys() >>.
1059              
1060             =cut
1061              
1062             sub pairkeys {
1063              
1064             package Hydrogen::ArrayRef::__SANDBOX__;
1065 0 0   0 1 0 @_ == 0
1066             or Hydrogen::croak( "Wrong number of parameters for pairkeys; usage: "
1067             . "Hydrogen::Topic::ArrayRef::pairkeys()" );
1068 0         0 &List::Util::pairkeys( @{$_} );
  0         0  
1069             }
1070              
1071             =head2 C<< pairmap( $coderef ) >>
1072              
1073             Operates on C<< $_ >>, which must be a reference to an array.
1074              
1075             Arguments: B<< CodeRef >>.
1076              
1077             Like C<< List::Util::pairmap() >>.
1078              
1079             =cut
1080              
1081             sub pairmap {
1082              
1083             package Hydrogen::ArrayRef::__SANDBOX__;
1084 0     0 1 0 @_ = do {
1085 0         0 my ( %tmp, $tmp );
1086              
1087 0 0       0 @_ == 1
1088             or Hydrogen::croak(
1089             "Wrong number of parameters in signature for %s: got %d, %s",
1090             "pairmap", scalar(@_), "expected exactly 1 parameters" );
1091              
1092             # Parameter $_[0] (type: CodeRef)
1093 0 0       0 ( ref( $_[0] ) eq 'CODE' )
1094             or Hydrogen::croak(
1095             "Type check failed in signature for pairmap: %s should be %s",
1096             "\$_[0]", "CodeRef" );
1097              
1098 0         0 (@_);
1099             };
1100 0     0   0 List::Util::pairmap { $_[0]->($_) } @{$_};
  0         0  
  0         0  
1101             }
1102              
1103             =head2 C<< pairs() >>
1104              
1105             Operates on C<< $_ >>, which must be a reference to an array.
1106              
1107             Like C<< List::Util::pairs() >>.
1108              
1109             =cut
1110              
1111             sub pairs {
1112              
1113             package Hydrogen::ArrayRef::__SANDBOX__;
1114 0 0   0 1 0 @_ == 0
1115             or Hydrogen::croak( "Wrong number of parameters for pairs; usage: "
1116             . "Hydrogen::Topic::ArrayRef::pairs()" );
1117 0         0 &List::Util::pairs( @{$_} );
  0         0  
1118             }
1119              
1120             =head2 C<< pairvalues() >>
1121              
1122             Operates on C<< $_ >>, which must be a reference to an array.
1123              
1124             Like C<< List::Util::pairvalues() >>.
1125              
1126             =cut
1127              
1128             sub pairvalues {
1129              
1130             package Hydrogen::ArrayRef::__SANDBOX__;
1131 0 0   0 1 0 @_ == 0
1132             or Hydrogen::croak( "Wrong number of parameters for pairvalues; usage: "
1133             . "Hydrogen::Topic::ArrayRef::pairvalues()" );
1134 0         0 &List::Util::pairvalues( @{$_} );
  0         0  
1135             }
1136              
1137             =head2 C<< pick_random( $count ) >>
1138              
1139             Operates on C<< $_ >>, which must be a reference to an array.
1140              
1141             Arguments: B<< Optional[Int] >>.
1142              
1143             If no C<< $count >> is given, returns one element of the array at random. If C<< $count >> is given, creates a new array with that many random elements from the original array (or fewer if the original array is not long enough) and returns that as an arrayref or list depending on context
1144              
1145             =cut
1146              
1147             {
1148             my $__signature;
1149              
1150             sub pick_random {
1151              
1152             package Hydrogen::ArrayRef::__SANDBOX__;
1153             $__signature ||= sub {
1154 0     0   0 my ( %tmp, $tmp );
1155              
1156 0 0       0 @_ >= 0
1157             or Hydrogen::croak(
1158             "Wrong number of parameters in signature for %s: got %d, %s",
1159             "pick_random", scalar(@_), "expected exactly 0 parameters" );
1160              
1161             # Parameter $_[0] (type: Optional[Int])
1162 0 0       0 $#_ >= 0
1163             or return (@_);
1164             (
1165 0 0       0 do {
1166 0         0 my $tmp = $_[0];
1167 0 0 0     0 defined($tmp) and !ref($tmp) and $tmp =~ /\A-?[0-9]+\z/;
1168             }
1169             )
1170             or Hydrogen::croak(
1171             "Type check failed in signature for pick_random: %s should be %s",
1172             "\$_[0]", "Optional[Int]"
1173             );
1174              
1175 0         0 (@_);
1176 0   0 0 1 0 };
1177 0         0 @_ = &$__signature;
1178 0         0 my @shv_tmp = List::Util::shuffle( @{$_} );
  0         0  
1179 0         0 my $shv_count = $_[0];
1180 0 0       0 $shv_count = @{$_} if $shv_count > @{$_};
  0         0  
  0         0  
1181 0 0       0 $shv_count = @{$_} + $shv_count if $shv_count < 0;
  0         0  
1182 0 0 0     0 if ( wantarray and ( 0 + @_ ) ) { @shv_tmp[ 0 .. $shv_count - 1 ] }
  0 0       0  
1183 0         0 elsif ( ( 0 + @_ ) ) { [ @shv_tmp[ 0 .. $shv_count - 1 ] ] }
1184 0         0 else { $shv_tmp[0] }
1185             }
1186             }
1187              
1188             =head2 C<< pop() >>
1189              
1190             Operates on C<< $_ >>, which must be a reference to an array.
1191              
1192             Removes the last element from the array and returns it.
1193              
1194             =cut
1195              
1196             sub pop {
1197              
1198             package Hydrogen::ArrayRef::__SANDBOX__;
1199 2 50   2 1 41630 @_ == 0
1200             or Hydrogen::croak( "Wrong number of parameters for pop; usage: "
1201             . "Hydrogen::Topic::ArrayRef::pop()" );
1202 2         5 1;
1203 2         4 pop( @{$_} );
  2         16  
1204             }
1205              
1206             =head2 C<< print( $fh?, $with? ) >>
1207              
1208             Operates on C<< $_ >>, which must be a reference to an array.
1209              
1210             Arguments: B<< Optional[FileHandle] >>, B<< Optional[Str] >>.
1211              
1212             Prints a string joining all the elements in the array; if C<< $fh >> is omitted, defaults to STDOUT; if C<< $with >> is omitted, defaults to a comma.
1213              
1214             =cut
1215              
1216             {
1217             my $__signature;
1218              
1219             sub print {
1220              
1221             package Hydrogen::ArrayRef::__SANDBOX__;
1222             $__signature ||= sub {
1223 0     0   0 my ( %tmp, $tmp );
1224              
1225 0 0       0 @_ >= 0
1226             or Hydrogen::croak(
1227             "Wrong number of parameters in signature for %s: got %d, %s",
1228             "print", scalar(@_), "expected exactly 0 parameters" );
1229              
1230             # Parameter $_[0] (type: Optional[FileHandle])
1231 0 0       0 $#_ >= 0
1232             or return (@_);
1233             (
1234 0 0       0 do {
1235              
1236             package Hydrogen::ArrayRef::__SANDBOX__;
1237 2     2   12400 use Scalar::Util ();
  2         5  
  2         7335  
1238 0 0 0     0 ( ref( $_[0] ) && Scalar::Util::openhandle( $_[0] ) )
      0        
1239             or ( Scalar::Util::blessed( $_[0] )
1240             && $_[0]->isa("IO::Handle") );
1241             }
1242             )
1243             or Hydrogen::croak(
1244             "Type check failed in signature for print: %s should be %s",
1245             "\$_[0]", "Optional[FileHandle]" );
1246              
1247             # Parameter $_[1] (type: Optional[Str])
1248 0 0       0 $#_ >= 1
1249             or return (@_);
1250 0 0       0 do {
1251              
1252             package Hydrogen::ArrayRef::__SANDBOX__;
1253 0 0       0 defined( $_[1] ) and do {
1254 0 0       0 ref( \$_[1] ) eq 'SCALAR'
1255             or ref( \( my $val = $_[1] ) ) eq 'SCALAR';
1256             }
1257             }
1258             or Hydrogen::croak(
1259             "Type check failed in signature for print: %s should be %s",
1260             "\$_[1]", "Optional[Str]" );
1261              
1262 0         0 (@_);
1263 0   0 0 1 0 };
1264 0         0 @_ = &$__signature;
1265 0 0       0 my $shv_param_with = ( ( 0 + @_ ) > 1 ) ? $_[1] : q[,];
1266 0 0       0 print { $_[0] || *STDOUT } join( $shv_param_with, @{$_} );
  0         0  
  0         0  
1267             }
1268             }
1269              
1270             =head2 C<< product() >>
1271              
1272             Operates on C<< $_ >>, which must be a reference to an array.
1273              
1274             Like C<< List::Util::product() >>.
1275              
1276             =cut
1277              
1278             sub product {
1279              
1280             package Hydrogen::ArrayRef::__SANDBOX__;
1281 0 0   0 1 0 @_ == 0
1282             or Hydrogen::croak( "Wrong number of parameters for product; usage: "
1283             . "Hydrogen::Topic::ArrayRef::product()" );
1284 0         0 &List::Util::product( 1, @{$_} );
  0         0  
1285             }
1286              
1287             =head2 C<< push( @values ) >>
1288              
1289             Operates on C<< $_ >>, which must be a reference to an array.
1290              
1291             Adds elements to the end of the array.
1292              
1293             =cut
1294              
1295             sub push {
1296              
1297             package Hydrogen::ArrayRef::__SANDBOX__;
1298 1     1 1 15825 1;
1299 1         3 push( @{$_}, @_ );
  1         3  
1300             }
1301              
1302             =head2 C<< reduce( $coderef ) >>
1303              
1304             Operates on C<< $_ >>, which must be a reference to an array.
1305              
1306             Arguments: B<< CodeRef >>.
1307              
1308             Like C<< List::Util::reduce() >>.
1309              
1310             =cut
1311              
1312             sub reduce {
1313              
1314             package Hydrogen::ArrayRef::__SANDBOX__;
1315 0     0 1 0 @_ = do {
1316 0         0 my ( %tmp, $tmp );
1317              
1318 0 0       0 @_ == 1
1319             or Hydrogen::croak(
1320             "Wrong number of parameters in signature for %s: got %d, %s",
1321             "reduce", scalar(@_), "expected exactly 1 parameters" );
1322              
1323             # Parameter $_[0] (type: CodeRef)
1324 0 0       0 ( ref( $_[0] ) eq 'CODE' )
1325             or Hydrogen::croak(
1326             "Type check failed in signature for reduce: %s should be %s",
1327             "\$_[0]", "CodeRef" );
1328              
1329 0         0 (@_);
1330             };
1331 0         0 my $shv_callback = $_[0];
1332 0     0   0 List::Util::reduce { $shv_callback->( $a, $b ) } @{$_};
  0         0  
  0         0  
1333             }
1334              
1335             =head2 C<< reductions( $coderef ) >>
1336              
1337             Operates on C<< $_ >>, which must be a reference to an array.
1338              
1339             Arguments: B<< CodeRef >>.
1340              
1341             Like C<< List::Util::reductions() >>.
1342              
1343             =cut
1344              
1345             sub reductions {
1346              
1347             package Hydrogen::ArrayRef::__SANDBOX__;
1348 0     0 1 0 @_ = do {
1349 0         0 my ( %tmp, $tmp );
1350              
1351 0 0       0 @_ == 1
1352             or Hydrogen::croak(
1353             "Wrong number of parameters in signature for %s: got %d, %s",
1354             "reductions", scalar(@_), "expected exactly 1 parameters" );
1355              
1356             # Parameter $_[0] (type: CodeRef)
1357 0 0       0 ( ref( $_[0] ) eq 'CODE' )
1358             or Hydrogen::croak(
1359             "Type check failed in signature for reductions: %s should be %s",
1360             "\$_[0]", "CodeRef" );
1361              
1362 0         0 (@_);
1363             };
1364 0         0 my $shv_callback = $_[0];
1365 0     0   0 List::Util::reductions { $shv_callback->( $a, $b ) } @{$_};
  0         0  
  0         0  
1366             }
1367              
1368             =head2 C<< reset() >>
1369              
1370             Operates on C<< $_ >>, which must be a reference to an array.
1371              
1372             Resets the original value to its default value, or an empty arrayref if it has no default.
1373              
1374             =cut
1375              
1376             sub reset {
1377              
1378             package Hydrogen::ArrayRef::__SANDBOX__;
1379 1 50   1 1 14226 @_ == 0
1380             or Hydrogen::croak( "Wrong number of parameters for reset; usage: "
1381             . "Hydrogen::Topic::ArrayRef::reset()" );
1382             (
1383 1         3 @{$_} = @{
1384 1         3 +do {
  1         3  
1385 1         2 my $shv_final_unchecked = [];
1386 1         2 do {
1387 1 50       5 ( ref($shv_final_unchecked) eq 'ARRAY' )
1388             or Hydrogen::croak(
1389             "Type check failed for reset: expected %s, got value %s",
1390             "ArrayRef", $shv_final_unchecked
1391             );
1392 1         3 $shv_final_unchecked;
1393             };
1394             }
1395             }
1396             );
1397             }
1398              
1399             =head2 C<< reverse() >>
1400              
1401             Operates on C<< $_ >>, which must be a reference to an array.
1402              
1403             Returns the reversed array in list context.
1404              
1405             =cut
1406              
1407             sub reverse {
1408              
1409             package Hydrogen::ArrayRef::__SANDBOX__;
1410 0 0   0 1 0 @_ == 0
1411             or Hydrogen::croak( "Wrong number of parameters for reverse; usage: "
1412             . "Hydrogen::Topic::ArrayRef::reverse()" );
1413 0         0 reverse @{$_};
  0         0  
1414             }
1415              
1416             =head2 C<< sample( $count ) >>
1417              
1418             Operates on C<< $_ >>, which must be a reference to an array.
1419              
1420             Arguments: B<< Int >>.
1421              
1422             Like C<< List::Util::sample() >>.
1423              
1424             =cut
1425              
1426             sub sample {
1427              
1428             package Hydrogen::ArrayRef::__SANDBOX__;
1429 0     0 1 0 @_ = do {
1430 0         0 my ( %tmp, $tmp );
1431              
1432 0 0       0 @_ == 1
1433             or Hydrogen::croak(
1434             "Wrong number of parameters in signature for %s: got %d, %s",
1435             "sample", scalar(@_), "expected exactly 1 parameters" );
1436              
1437             # Parameter $_[0] (type: Int)
1438             (
1439 0 0       0 do {
1440 0         0 my $tmp = $_[0];
1441 0 0 0     0 defined($tmp) and !ref($tmp) and $tmp =~ /\A-?[0-9]+\z/;
1442             }
1443             )
1444             or Hydrogen::croak(
1445             "Type check failed in signature for sample: %s should be %s",
1446             "\$_[0]", "Int" );
1447              
1448 0         0 (@_);
1449             };
1450 0         0 &List::Util::sample( $_[0], @{$_} );
  0         0  
1451             }
1452              
1453             =head2 C<< set( $index, $value ) >>
1454              
1455             Operates on C<< $_ >>, which must be a reference to an array.
1456              
1457             Arguments: B<< Int >>, B<< Any >>.
1458              
1459             Sets the element with the given index to the supplied value.
1460              
1461             =cut
1462              
1463             sub set {
1464              
1465             package Hydrogen::ArrayRef::__SANDBOX__;
1466 1     1 1 17669 @_ = do {
1467 1         3 my ( %tmp, $tmp );
1468              
1469 1 50       6 @_ == 2
1470             or Hydrogen::croak(
1471             "Wrong number of parameters in signature for %s: got %d, %s",
1472             "set", scalar(@_), "expected exactly 2 parameters" );
1473              
1474             # Parameter $_[0] (type: Int)
1475             (
1476 1 50       2 do {
1477 1         2 my $tmp = $_[0];
1478 1 50 33     20 defined($tmp) and !ref($tmp) and $tmp =~ /\A-?[0-9]+\z/;
1479             }
1480             )
1481             or Hydrogen::croak(
1482             "Type check failed in signature for set: %s should be %s",
1483             "\$_[0]", "Int" );
1484              
1485             # Parameter $_[1] (type: Any)
1486 1         2 1; # ... nothing to do
1487              
1488 1         5 (@_);
1489             };
1490 1         3 1;
1491 1         5 ($_)->[ $_[0] ] = $_[1];
1492             }
1493              
1494             =head2 C<< shallow_clone() >>
1495              
1496             Operates on C<< $_ >>, which must be a reference to an array.
1497              
1498             Creates a new arrayref with the same elements as the original.
1499              
1500             =cut
1501              
1502             sub shallow_clone {
1503              
1504             package Hydrogen::ArrayRef::__SANDBOX__;
1505 0 0   0 1 0 @_ == 0
1506             or
1507             Hydrogen::croak( "Wrong number of parameters for shallow_clone; usage: "
1508             . "Hydrogen::Topic::ArrayRef::shallow_clone()" );
1509 0         0 [ @{$_} ];
  0         0  
1510             }
1511              
1512             =head2 C<< shift() >>
1513              
1514             Operates on C<< $_ >>, which must be a reference to an array.
1515              
1516             Removes an element from the start of the array and returns it.
1517              
1518             =cut
1519              
1520             sub shift {
1521              
1522             package Hydrogen::ArrayRef::__SANDBOX__;
1523 2 50   2 1 13467 @_ == 0
1524             or Hydrogen::croak( "Wrong number of parameters for shift; usage: "
1525             . "Hydrogen::Topic::ArrayRef::shift()" );
1526 2         4 1;
1527 2         5 shift( @{$_} );
  2         23  
1528             }
1529              
1530             =head2 C<< shuffle() >>
1531              
1532             Operates on C<< $_ >>, which must be a reference to an array.
1533              
1534             Returns the array in a random order; can be called in list context or scalar context and will return an arrayref in the latter case.
1535              
1536             =cut
1537              
1538             sub shuffle {
1539              
1540             package Hydrogen::ArrayRef::__SANDBOX__;
1541 0 0   0 1 0 @_ == 0
1542             or Hydrogen::croak( "Wrong number of parameters for shuffle; usage: "
1543             . "Hydrogen::Topic::ArrayRef::shuffle()" );
1544 0         0 my @shv_return = List::Util::shuffle( @{$_} );
  0         0  
1545 0 0       0 wantarray ? @shv_return : \@shv_return;
1546             }
1547              
1548             =head2 C<< shuffle_in_place() >>
1549              
1550             Operates on C<< $_ >>, which must be a reference to an array.
1551              
1552             Rearranges the array in a random order, and changes the original value to point to the new order.
1553              
1554             =cut
1555              
1556             sub shuffle_in_place {
1557              
1558             package Hydrogen::ArrayRef::__SANDBOX__;
1559 0 0   0 1 0 @_ == 0
1560             or Hydrogen::croak(
1561             "Wrong number of parameters for shuffle_in_place; usage: "
1562             . "Hydrogen::Topic::ArrayRef::shuffle_in_place()" );
1563 0         0 1;
1564 0         0 my @shv_return = List::Util::shuffle( @{$_} );
  0         0  
1565 0         0 ( @{$_} = @{ +\@shv_return } );
  0         0  
  0         0  
1566             }
1567              
1568             =head2 C<< sort( $coderef? ) >>
1569              
1570             Operates on C<< $_ >>, which must be a reference to an array.
1571              
1572             Arguments: B<< Optional[CodeRef] >>.
1573              
1574             Like C from L.
1575              
1576             =cut
1577              
1578             {
1579             my $__signature;
1580              
1581             sub sort {
1582              
1583             package Hydrogen::ArrayRef::__SANDBOX__;
1584             $__signature ||= sub {
1585 0     0   0 my ( %tmp, $tmp );
1586              
1587 0 0       0 @_ >= 0
1588             or Hydrogen::croak(
1589             "Wrong number of parameters in signature for %s: got %d, %s",
1590             "sort", scalar(@_), "expected exactly 0 parameters" );
1591              
1592             # Parameter $_[0] (type: Optional[CodeRef])
1593 0 0       0 $#_ >= 0
1594             or return (@_);
1595 0 0       0 ( ref( $_[0] ) eq 'CODE' )
1596             or Hydrogen::croak(
1597             "Type check failed in signature for sort: %s should be %s",
1598             "\$_[0]", "Optional[CodeRef]" );
1599              
1600 0         0 (@_);
1601 0   0 0 1 0 };
1602 0         0 @_ = &$__signature;
1603             my @shv_return =
1604 0 0       0 $_[0] ? ( sort { $_[0]->( $a, $b ) } @{$_} ) : ( sort @{$_} );
  0         0  
  0         0  
  0         0  
1605             }
1606             }
1607              
1608             =head2 C<< sort_in_place( $coderef? ) >>
1609              
1610             Operates on C<< $_ >>, which must be a reference to an array.
1611              
1612             Arguments: B<< Optional[CodeRef] >>.
1613              
1614             Like C from L, but changes the original value to point to the newly sorted array.
1615              
1616             =cut
1617              
1618             {
1619             my $__signature;
1620              
1621             sub sort_in_place {
1622              
1623             package Hydrogen::ArrayRef::__SANDBOX__;
1624             $__signature ||= sub {
1625 0     0   0 my ( %tmp, $tmp );
1626              
1627 0 0       0 @_ >= 0
1628             or Hydrogen::croak(
1629             "Wrong number of parameters in signature for %s: got %d, %s",
1630             "sort_in_place", scalar(@_), "expected exactly 0 parameters" );
1631              
1632             # Parameter $_[0] (type: Optional[CodeRef])
1633 0 0       0 $#_ >= 0
1634             or return (@_);
1635 0 0       0 ( ref( $_[0] ) eq 'CODE' )
1636             or Hydrogen::croak(
1637             "Type check failed in signature for sort_in_place: %s should be %s",
1638             "\$_[0]", "Optional[CodeRef]"
1639             );
1640              
1641 0         0 (@_);
1642 0   0 0 1 0 };
1643 0         0 @_ = &$__signature;
1644 0         0 1;
1645             my @shv_return =
1646 0 0       0 $_[0] ? ( sort { $_[0]->( $a, $b ) } @{$_} ) : ( sort @{$_} );
  0         0  
  0         0  
  0         0  
1647 0         0 ( @{$_} = @{ +\@shv_return } );
  0         0  
  0         0  
1648             }
1649             }
1650              
1651             =head2 C<< splice( $index, $length, @values ) >>
1652              
1653             Operates on C<< $_ >>, which must be a reference to an array.
1654              
1655             Like C from L.
1656              
1657             =cut
1658              
1659             sub splice {
1660              
1661             package Hydrogen::ArrayRef::__SANDBOX__;
1662 0 0   0 1 0 @_ >= 1
1663             or Hydrogen::croak( "Wrong number of parameters for splice; usage: "
1664             . "Hydrogen::Topic::ArrayRef::splice( \$index, \$length, \@values )"
1665             );
1666 0 0       0 if ( ( 0 + @_ ) >= 1 ) {
1667 0         0 do {
1668             (
1669 0 0       0 do {
1670 0         0 my $tmp = $_[0];
1671 0 0 0     0 defined($tmp) and !ref($tmp) and $tmp =~ /\A-?[0-9]+\z/;
1672             }
1673             )
1674             or Hydrogen::croak(
1675             "Type check failed for splice: expected %s, got value %s",
1676             "Int", $_[0] );
1677 0         0 $_[0];
1678             };
1679             }
1680             ;
1681 0 0       0 if ( ( 0 + @_ ) >= 2 ) {
1682 0         0 do {
1683             (
1684 0 0       0 do {
1685 0         0 my $tmp = $_[1];
1686 0 0 0     0 defined($tmp) and !ref($tmp) and $tmp =~ /\A-?[0-9]+\z/;
1687             }
1688             )
1689             or Hydrogen::croak(
1690             "Type check failed for splice: expected %s, got value %s",
1691             "Int", $_[1] );
1692 0         0 $_[1];
1693             };
1694             }
1695 0         0 my ( $shv_index, $shv_length, @shv_values ) = @_;
1696 0         0 splice( @{$_}, $shv_index, $shv_length, @shv_values );
  0         0  
1697             }
1698              
1699             =head2 C<< sum() >>
1700              
1701             Operates on C<< $_ >>, which must be a reference to an array.
1702              
1703             Like C<< List::Util::sum0() >>.
1704              
1705             =cut
1706              
1707             sub sum {
1708              
1709             package Hydrogen::ArrayRef::__SANDBOX__;
1710 0 0   0 1 0 @_ == 0
1711             or Hydrogen::croak( "Wrong number of parameters for sum; usage: "
1712             . "Hydrogen::Topic::ArrayRef::sum()" );
1713 0         0 &List::Util::sum( 0, @{$_} );
  0         0  
1714             }
1715              
1716             =head2 C<< tail( $count ) >>
1717              
1718             Operates on C<< $_ >>, which must be a reference to an array.
1719              
1720             Arguments: B<< Int >>.
1721              
1722             Returns the last C<< $count >> elements of the array in list context.
1723              
1724             =cut
1725              
1726             sub tail {
1727              
1728             package Hydrogen::ArrayRef::__SANDBOX__;
1729 0     0 1 0 @_ = do {
1730 0         0 my ( %tmp, $tmp );
1731              
1732 0 0       0 @_ == 1
1733             or Hydrogen::croak(
1734             "Wrong number of parameters in signature for %s: got %d, %s",
1735             "tail", scalar(@_), "expected exactly 1 parameters" );
1736              
1737             # Parameter $_[0] (type: Int)
1738             (
1739 0 0       0 do {
1740 0         0 my $tmp = $_[0];
1741 0 0 0     0 defined($tmp) and !ref($tmp) and $tmp =~ /\A-?[0-9]+\z/;
1742             }
1743             )
1744             or Hydrogen::croak(
1745             "Type check failed in signature for tail: %s should be %s",
1746             "\$_[0]", "Int" );
1747              
1748 0         0 (@_);
1749             };
1750 0         0 my $shv_count = $_[0];
1751 0 0       0 $shv_count = @{$_} if $shv_count > @{$_};
  0         0  
  0         0  
1752 0 0       0 $shv_count = @{$_} + $shv_count if $shv_count < 0;
  0         0  
1753 0         0 my $shv_start = scalar( @{$_} ) - $shv_count;
  0         0  
1754 0         0 my $shv_end = scalar( @{$_} ) - 1;
  0         0  
1755 0         0 ( @{$_} )[ $shv_start .. $shv_end ];
  0         0  
1756             }
1757              
1758             =head2 C<< uniq() >>
1759              
1760             Operates on C<< $_ >>, which must be a reference to an array.
1761              
1762             Returns the array filtered to remove duplicates; can be called in list context or scalar context and will return an arrayref in the latter case.
1763              
1764             =cut
1765              
1766             sub uniq {
1767              
1768             package Hydrogen::ArrayRef::__SANDBOX__;
1769 0 0   0 1 0 @_ == 0
1770             or Hydrogen::croak( "Wrong number of parameters for uniq; usage: "
1771             . "Hydrogen::Topic::ArrayRef::uniq()" );
1772 0         0 my @shv_return = List::Util::uniq( @{$_} );
  0         0  
1773 0 0       0 wantarray ? @shv_return : \@shv_return;
1774             }
1775              
1776             =head2 C<< uniq_in_place() >>
1777              
1778             Operates on C<< $_ >>, which must be a reference to an array.
1779              
1780             Filters the array to remove duplicates, and changes the original value to point to the filtered array.
1781              
1782             =cut
1783              
1784             sub uniq_in_place {
1785              
1786             package Hydrogen::ArrayRef::__SANDBOX__;
1787 0 0   0 1 0 @_ == 0
1788             or
1789             Hydrogen::croak( "Wrong number of parameters for uniq_in_place; usage: "
1790             . "Hydrogen::Topic::ArrayRef::uniq_in_place()" );
1791 0         0 1;
1792 0         0 my @shv_return = List::Util::uniq( @{$_} );
  0         0  
1793 0         0 ( @{$_} = @{ +\@shv_return } );
  0         0  
  0         0  
1794             }
1795              
1796             =head2 C<< uniqnum() >>
1797              
1798             Operates on C<< $_ >>, which must be a reference to an array.
1799              
1800             Returns the array filtered to remove duplicates numerically; can be called in list context or scalar context and will return an arrayref in the latter case.
1801              
1802             =cut
1803              
1804             sub uniqnum {
1805              
1806             package Hydrogen::ArrayRef::__SANDBOX__;
1807 0 0   0 1 0 @_ == 0
1808             or Hydrogen::croak( "Wrong number of parameters for uniqnum; usage: "
1809             . "Hydrogen::Topic::ArrayRef::uniqnum()" );
1810 0         0 my @shv_return = List::Util::uniqnum( @{$_} );
  0         0  
1811 0 0       0 wantarray ? @shv_return : \@shv_return;
1812             }
1813              
1814             =head2 C<< uniqnum_in_place() >>
1815              
1816             Operates on C<< $_ >>, which must be a reference to an array.
1817              
1818             Filters the array to remove duplicates numerically, and changes the original value to point to the filtered array.
1819              
1820             =cut
1821              
1822             sub uniqnum_in_place {
1823              
1824             package Hydrogen::ArrayRef::__SANDBOX__;
1825 0 0   0 1 0 @_ == 0
1826             or Hydrogen::croak(
1827             "Wrong number of parameters for uniqnum_in_place; usage: "
1828             . "Hydrogen::Topic::ArrayRef::uniqnum_in_place()" );
1829 0         0 1;
1830 0         0 my @shv_return = List::Util::uniqnum( @{$_} );
  0         0  
1831 0         0 ( @{$_} = @{ +\@shv_return } );
  0         0  
  0         0  
1832             }
1833              
1834             =head2 C<< uniqstr() >>
1835              
1836             Operates on C<< $_ >>, which must be a reference to an array.
1837              
1838             Returns the array filtered to remove duplicates stringwise; can be called in list context or scalar context and will return an arrayref in the latter case.
1839              
1840             =cut
1841              
1842             sub uniqstr {
1843              
1844             package Hydrogen::ArrayRef::__SANDBOX__;
1845 0 0   0 1 0 @_ == 0
1846             or Hydrogen::croak( "Wrong number of parameters for uniqstr; usage: "
1847             . "Hydrogen::Topic::ArrayRef::uniqstr()" );
1848 0         0 my @shv_return = List::Util::uniqstr( @{$_} );
  0         0  
1849 0 0       0 wantarray ? @shv_return : \@shv_return;
1850             }
1851              
1852             =head2 C<< uniqstr_in_place() >>
1853              
1854             Operates on C<< $_ >>, which must be a reference to an array.
1855              
1856             Filters the array to remove duplicates stringwise, and changes the original value to point to the filtered array.
1857              
1858             =cut
1859              
1860             sub uniqstr_in_place {
1861              
1862             package Hydrogen::ArrayRef::__SANDBOX__;
1863 0 0   0 1 0 @_ == 0
1864             or Hydrogen::croak(
1865             "Wrong number of parameters for uniqstr_in_place; usage: "
1866             . "Hydrogen::Topic::ArrayRef::uniqstr_in_place()" );
1867 0         0 1;
1868 0         0 my @shv_return = List::Util::uniqstr( @{$_} );
  0         0  
1869 0         0 ( @{$_} = @{ +\@shv_return } );
  0         0  
  0         0  
1870             }
1871              
1872             =head2 C<< unshift( @values ) >>
1873              
1874             Operates on C<< $_ >>, which must be a reference to an array.
1875              
1876             Adds an element to the start of the array.
1877              
1878             =cut
1879              
1880             sub unshift {
1881              
1882             package Hydrogen::ArrayRef::__SANDBOX__;
1883 1     1 1 68062 1;
1884 1         4 unshift( @{$_}, @_ );
  1         5  
1885             }
1886              
1887             1;
1888              
1889             =head1 EXPORT
1890              
1891             No functions are exported by this module by default. To import them all (this is usually a bad idea), use:
1892              
1893             use Hydrogen::Topic::ArrayRef -all;
1894              
1895             To import a particular function, use:
1896              
1897             use Hydrogen::Topic::ArrayRef 'all_true';
1898              
1899             To rename functions:
1900              
1901             use Hydrogen::Topic::ArrayRef 'all_true' => { -as => 'myfunc' };
1902              
1903             On Perl 5.37.2+ (or if L is installed) you can import lexically:
1904              
1905             use Hydrogen::Topic::ArrayRef -lexical, 'all_true';
1906              
1907             See L for more hints on importing.
1908              
1909             =head1 BUGS
1910              
1911             Please report any bugs to
1912             L.
1913              
1914             =head1 SEE ALSO
1915              
1916             L,
1917             L,
1918             L,
1919             L,
1920             L,
1921             L,
1922             L.
1923              
1924             =head1 AUTHOR
1925              
1926             Toby Inkster Etobyink@cpan.orgE.
1927              
1928             =head1 COPYRIGHT AND LICENCE
1929              
1930             This software is copyright (c) 2022-2025 by Toby Inkster.
1931              
1932             This is free software; you can redistribute it and/or modify it under
1933             the same terms as the Perl 5 programming language system itself.
1934              
1935             =head1 DISCLAIMER OF WARRANTIES
1936              
1937             THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
1938             WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
1939             MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
1940