=begin pod

=TITLE class Any

=SUBTITLE Thing/object

    class Any is Mu { ... }

While L<Mu|/type/Mu> is the root of the Perl 6 class hierarchy, C<Any> is the class
that serves as a default base class for new classes, and as the base class for
most built-in classes.

Since Perl 6 intentionally confuses items and single-element lists, most
methods in C<Any> are also present on class L<List|/type/List>, and coerce to
List or a list-like type.

=head1 Methods

=head2 method ACCEPTS

Defined as:

    multi method ACCEPTS(Any:D: Mu $other)

Usage:

    EXPR.ACCEPTS(EXPR);

Returns C<True> if C<$other === self> (i.e. it checks object identity).

Many built-in types override this for more specific comparisons

=head2 method any

Defined as:

    method any() returns Junction:D

Usage:

    LIST.any

Interprets the invocant as a list and creates an
C<any>-L<Junction|/type/Junction> from it.

    say so 2 == <1 2 3>.any;        # True
    say so 5 == <1 2 3>.any;        # False

=head2 method all

Defined as:

    method all() returns Junction:D

Usage:

    LIST.any

Interprets the invocant as a list and creates an
C<all>-L<Junction|/type/Junction> from it.

    say so 1 < <2 3 4>.all;         # True
    say so 3 < <2 3 4>.all;         # False

=head2 method one

Defined as:

    method one() returns Junction:D

Usage:

    LIST.one

Interprets the invocant as a list and creates an
C<one>-L<Junction|/type/Junction> from it.

    say so 1 == (1, 2, 3).one;      # True
    say so 1 == (1, 2, 1).one;      # False

=head2 method none

Defined as:

    method none() returns Junction:D

Usage:

    LIST.none

Interprets the invocant as a list and creates an
C<none>-L<Junction|/type/Junction> from it.

    say so 1 == (1, 2, 3).none;     # False
    say so 4 == (1, 2, 3).none;     # True

=head2 method list

Interprets the invocant as a list, and returns that L<List|/type/List>.

    say 42.list.^name;           # List
    say 42.list.elems;           # 1

=head2 routine reverse

Defined as:

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

Usage:

    reverse(LIST)
    LIST.reverse

Returns a list with the same elements in reverse order.

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

Examples:

    say <hello world!>.reverse      #  world! hello
    say reverse ^10                 # 9 8 7 6 5 4 3 2 1 0

=head2 method sort

Sorts iterables with C<infix:<cmp>> or given code object.

Examples:

    say <b c a>.sort;                           # a b c
    say 'bca'.comb.sort.join;                   # abc
    say 'bca'.comb.sort({$^b cmp $^a}).join;    # cba
    say '231'.comb.sort(&infix:«<=>»).join;     # 123

=head2 method flat

Interprets the invocant as a list, flattens it, and returns that list.

    say ((1, 2), (3)).elems;        # 2
    say ((1, 2), (3)).flat.elems;   # 3

=head2 method eager

Interprets the invocant as a list, evaluates it eagerly, and returns that
list.

    say (1..10).eager;              # 1 2 3 4 5 6 7 8 9 10

=head2 method elems

Interprets the invocant as a list, and returns the number of elements in the
list.

    say 42.elems;                   # 1
    say <a b c>.elems;              # 3

=head2 method end

Interprets the invocant as a list, and returns the last index of that list.

    say 6.end;                      # 0
    say <a b c>.end;                # 2

=head2 method pairup

    method pairup() returns List

Interprets the invocant as a list, and constructs a list of
L<pairs|/type/Pair> from it, in the same way that assignment to a
L<Hash|/type/Hash> does. That is, it takes two consecutive elements and
constructs a pair from them, unless the item in the key position already is a
pair (in which case the pair is passed is passed through, and the next
list item, if any, is considered to be a key again).

    say (a => 1, 'b', 'c').pairup.perl;     # ("a" => 1, "b" => "c").list

=head2 sub exit

    sub exit(Int() $status = 0)

Exits the current process with return code C<$status>.

=comment TODO maybe find a better place to document &exit

=end pod

# vim: expandtab shiftwidth=4 ft=perl6
