<commit_before>=begin pod

=head1 List

    my class List is Iterable does Positional { .. }

C<List> stores items sequentially and potentially lazily.

Indexes into lists and arrays start at 0 by default.

You can assign to list elements if they are containers.  Use
Arrays to have every value of the list stored in a container.

=head2 Items, Flattening and Sigils

In Perl 6, assigning a C<List> to a scalar variable does not lose
information. The difference is that iteration generally treats a
list (or any other list-like object, like a C<Parcel> or an C<Array>)
inside a scalar as a single element.

    my @a = 1, 2, 3;
    for @a { }      # three iterations

    my $s = @a;
    for $s { }      # one iteration
    for @a.item { } # one iteration
    for $s.list { } # three iterations

Lists generally interpolate (flatten) unless they are accessed via
an item (scalar) container.

    my @a = 1, 2, 3;
    my @flat   = @a, @a;           # six elements
    my @nested = @a.item, @a.item; # two elemnts

C<.item> can often be written as C<$( ... )>, and on an array variable
even as C<$@a>.

=head2 Methods

=head3 elems

    multi sub    elems($list)  returns Int:D
    multi method elems(List:D:) returns Int:D

Returns the number of elements in the list.

=head3 end

    multi sub    end($list)  returns Int:D
    multi method end(List:D:) returns Int:D

Returns the index of the last element.

=head3 keys

    multi sub    keys($list)  returns List:D
    multi method keys(List:D:) returns List:D

Returns a list of indexes into the list (i.e., 0..(@list.elems-1)).

=head3 values

    multi sub    values($list)  returns List:D
    multi method values(List:D:) returns List:D

Returns a copy of the list.

=head3 kv

    multi sub    kv($list)  returns List:D
    multi method kv(List:D:) returns List:D

Returns an interleaved list of indexes and values. For example

    <a b c>.kv

Returns

    0, 'a', 1, 'b', 2, 'c'

=head3 pairs

    multi sub    pairs($list)   returns List:D
    multi method pairs(List:D:) returns List:D

Returns a list of pairs, with the indexes as keys and the list values as
values.

    <a b c>.pairs   # 0 => 'a', 1 => 'b', 2 => 'c'

=head3  join

    multi sub    join($separator, *@list) returns Str:D
    multi method join(List:D: $separator) returns Str:D

Treats the elements of the list as strings, interleaves them with
C<$separator> and concatenates everything into a single string.

Example:

    join ', ', <a b c>;     # 'a, b, c'

=head3 map

    multi sub    map(&code, *@elems) returns List:D
    multi method map(List:D: &code) returns List:D

Invokes C<&code> for each element and gathers the return values in another
list and returns it. This happens lazily, ie C<&code> is only invoked when
the return values are accessed.

=head3 grep

    multi sub    grep(Mu $matcher, *@elems) returns List:D
    multi method grep(List:D:  Mu $matcher) returns List:D

Returns a lazy list of elements against which C<$matcher> smart-matches.
The elements are returned in the order in which they appear in the original
list.

=head3 first

    multi sub    first(Mu $matcher, *@elems)
    multi method first(List:D:  Mu $matcher)

Returns the first item of the list which smart-matches against C<$matcher>.

=head3 classify

    multi sub    classify(&mapper, *@values) returns Hash:D
    multi method classify(List:D: &mapper)   returns Hash:D

C<classify> transforms a list or array of values into a hash
representing the classification of those values according to a mapper;
each hash key represents the classification for one or more of the
incoming list values, and the corresponding hash value contains
an array of those list values classified by the mapper into the category
of the associated key.  For example:

  my @list = (1, 7, 6, 3, 2);
  my %h = classify { $_ %% 2 ?? 'even' !! 'odd' }, @list;

Creates the hash C<< { even => [6, 2], odd => [1, 7, 3] } >> in C<%h>.

=head3 Bool

    multi method Bool(List:D:) returns Bool:D

Returns C<True> if the list has at least one element, and C<False>
for the empty list.

=head3 Str

    multi method Str(List:D:) returns Str:D

Stringifies the elements of the list and joins them with spaces
(same as C<.join(' ')>).

=head3 Int

    multi method Int(List:D:) return Int:D

Returns the number of elements in the list (same as C<.elems>).

=head3 pick

    multi method pick(List:D: $count = 1)

Returns C<$count> elements chosen at random and without repetition
from the invocant.  If C<*> is passed as C<$count>, all elements
from the invocant list are returned in a random sequence.

=head3 roll

    multi method roll(List:D: $count = 1)

Returns a lazy list of C<$count> elements, each randomly selected from the
list. Each random choice is made indepently, like a separate die roll
where each die face is a list element.

If C<*> is passed to C<$count>, a lazy, infinite list of randomly chosen
elements from the original list.

=head3 eager

    multi method eager(List:D:) returns List:D

Evaluates all elements in the list eagerly, and returns the invocant.
If a List signals that it is "known infinite", eager evaluation may
stop at the point where the infinity is detected.

=head3 reverse

    multi sub    reverse(*@list ) returns List:D
    multi method reverse(List:D:) returns List:D

Returns a list with the elements in reverse order.

=head3 rotate

    multi sub    rotate(@list,  Int:D $n = 1) returns List:D
    multi method rotate(List:D: Int:D $n = 1) returns List:D

Returns the list rotated by C<$n> elements.

    <a b c d e>.rotate(2);   # <c d e a b>
    <a b c d e>.rotate(-1);  # <e a b c d>
<commit_msg>Add a note about 'reverse' vs 'flip'.<commit_after>=begin pod

=head1 List

    my class List is Iterable does Positional { .. }

C<List> stores items sequentially and potentially lazily.

Indexes into lists and arrays start at 0 by default.

You can assign to list elements if they are containers.  Use
Arrays to have every value of the list stored in a container.

=head2 Items, Flattening and Sigils

In Perl 6, assigning a C<List> to a scalar variable does not lose
information. The difference is that iteration generally treats a
list (or any other list-like object, like a C<Parcel> or an C<Array>)
inside a scalar as a single element.

    my @a = 1, 2, 3;
    for @a { }      # three iterations

    my $s = @a;
    for $s { }      # one iteration
    for @a.item { } # one iteration
    for $s.list { } # three iterations

Lists generally interpolate (flatten) unless they are accessed via
an item (scalar) container.

    my @a = 1, 2, 3;
    my @flat   = @a, @a;           # six elements
    my @nested = @a.item, @a.item; # two elemnts

C<.item> can often be written as C<$( ... )>, and on an array variable
even as C<$@a>.

=head2 Methods

=head3 elems

    multi sub    elems($list)  returns Int:D
    multi method elems(List:D:) returns Int:D

Returns the number of elements in the list.

=head3 end

    multi sub    end($list)  returns Int:D
    multi method end(List:D:) returns Int:D

Returns the index of the last element.

=head3 keys

    multi sub    keys($list)  returns List:D
    multi method keys(List:D:) returns List:D

Returns a list of indexes into the list (i.e., 0..(@list.elems-1)).

=head3 values

    multi sub    values($list)  returns List:D
    multi method values(List:D:) returns List:D

Returns a copy of the list.

=head3 kv

    multi sub    kv($list)  returns List:D
    multi method kv(List:D:) returns List:D

Returns an interleaved list of indexes and values. For example

    <a b c>.kv

Returns

    0, 'a', 1, 'b', 2, 'c'

=head3 pairs

    multi sub    pairs($list)   returns List:D
    multi method pairs(List:D:) returns List:D

Returns a list of pairs, with the indexes as keys and the list values as
values.

    <a b c>.pairs   # 0 => 'a', 1 => 'b', 2 => 'c'

=head3  join

    multi sub    join($separator, *@list) returns Str:D
    multi method join(List:D: $separator) returns Str:D

Treats the elements of the list as strings, interleaves them with
C<$separator> and concatenates everything into a single string.

Example:

    join ', ', <a b c>;     # 'a, b, c'

=head3 map

    multi sub    map(&code, *@elems) returns List:D
    multi method map(List:D: &code) returns List:D

Invokes C<&code> for each element and gathers the return values in another
list and returns it. This happens lazily, ie C<&code> is only invoked when
the return values are accessed.

=head3 grep

    multi sub    grep(Mu $matcher, *@elems) returns List:D
    multi method grep(List:D:  Mu $matcher) returns List:D

Returns a lazy list of elements against which C<$matcher> smart-matches.
The elements are returned in the order in which they appear in the original
list.

=head3 first

    multi sub    first(Mu $matcher, *@elems)
    multi method first(List:D:  Mu $matcher)

Returns the first item of the list which smart-matches against C<$matcher>.

=head3 classify

    multi sub    classify(&mapper, *@values) returns Hash:D
    multi method classify(List:D: &mapper)   returns Hash:D

C<classify> transforms a list or array of values into a hash
representing the classification of those values according to a mapper;
each hash key represents the classification for one or more of the
incoming list values, and the corresponding hash value contains
an array of those list values classified by the mapper into the category
of the associated key.  For example:

  my @list = (1, 7, 6, 3, 2);
  my %h = classify { $_ %% 2 ?? 'even' !! 'odd' }, @list;

Creates the hash C<< { even => [6, 2], odd => [1, 7, 3] } >> in C<%h>.

=head3 Bool

    multi method Bool(List:D:) returns Bool:D

Returns C<True> if the list has at least one element, and C<False>
for the empty list.

=head3 Str

    multi method Str(List:D:) returns Str:D

Stringifies the elements of the list and joins them with spaces
(same as C<.join(' ')>).

=head3 Int

    multi method Int(List:D:) return Int:D

Returns the number of elements in the list (same as C<.elems>).

=head3 pick

    multi method pick(List:D: $count = 1)

Returns C<$count> elements chosen at random and without repetition
from the invocant.  If C<*> is passed as C<$count>, all elements
from the invocant list are returned in a random sequence.

=head3 roll

    multi method roll(List:D: $count = 1)

Returns a lazy list of C<$count> elements, each randomly selected from the
list. Each random choice is made indepently, like a separate die roll
where each die face is a list element.

If C<*> is passed to C<$count>, a lazy, infinite list of randomly chosen
elements from the original list.

=head3 eager

    multi method eager(List:D:) returns List:D

Evaluates all elements in the list eagerly, and returns the invocant.
If a List signals that it is "known infinite", eager evaluation may
stop at the point where the infinity is detected.

=head3 reverse

    multi sub    reverse(*@list ) returns List:D
    multi method reverse(List:D:) returns List:D

Returns a list with the elements in reverse order.

Note that C<reverse> always refers to reversing elements of a list;
to reverse the characters in a string, use X<flip>.

=head3 rotate

    multi sub    rotate(@list,  Int:D $n = 1) returns List:D
    multi method rotate(List:D: Int:D $n = 1) returns List:D

Returns the list rotated by C<$n> elements.

    <a b c d e>.rotate(2);   # <c d e a b>
    <a b c d e>.rotate(-1);  # <e a b c d>

{'fraction_non_alphanumeric': 0.09187155481669437, 'fraction_numerical': 0.009624639076034648, 'mean_word_length': 3.3394077448747153, 'pattern_counts': {'":': 0, '<': 73, '<?xml version=': 0, '>': 83, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4348531', 'n_tokens_mistral': 3739, 'n_tokens_neox': 3523, 'n_words': 1682}