=begin pod

=TITLE class ComplexStr

=SUBTITLE Dual Value Complex number and String

    class ComplexStr is Complex is Str {}

The dual value types (often referred to as L<allomorphs|/language/glossary#Allomorph>)
allow for the representation of a value as both a string and a numeric type, typically
they will be created for you when the context is "stringy" but they can be determined
to be numbers, such as in some L<quoting constructs|/language/quoting>:

    my $f = <42+0i>; say $f.WHAT; # OUTPUT: «(ComplexStr)␤»

As a subclass of both L«C<Complex>|/type/Complex» and L«C<Str>|/type/Str»,
a C<ComplexStr> will be accepted where either is expected. However,
C<ComplexStr> does not share object identity with C<Complex>- or C<Str>-only
variants:

    my $complex-str = < 42+0i >;
    my Complex $complex = $complex-str; # OK!
    my Str     $str     = $complex-str; # OK!
    say 42+0i ∈ <42+0i  55  1>; # False; ∈ operator cares about object identity

=head1 Methods

=head2 method new

    method new(Complex $i, Str $s)

The constructor requires both the C<Complex> and the C<Str> value, when constructing one
directly the values can be whatever is required:

    my $f = ComplexStr.new(42+0i, "forty two (but complicated)");
    say +$f; # OUTPUT: «42+0i␤»
    say ~$f; # OUTPUT: «"forty two (but complicated)"␤»

=head2 method Numeric

    method Numeric

The numeric coercion is applied when the C<ComplexStr> is used in a numeric context,
such as a numeric comparison or smart match against a numeric value. It will return
the C<Complex> value.

=head2 method Complex

    method Complex

Returns the C<Complex> value of the C<ComplexStr>.

=head2 method Str

Returns the string value of the C<ComplexStr>.

=head1 Operators

=head2 infix cmp

    multi sub infix:<cmp>(ComplexStr:D $a, ComplexStr:D $b)

Compare two C<ComplexStr> objects.  The comparison is done on the C<Complex> value first and
then on the C<Str> value. If you want to compare in a different order then you would
coerce to the C<Complex> or C<Str> values first:

    my $f = ComplexStr.new(42+0i, "smaller");
    my $g = ComplexStr.new(43+0i, "larger");
    say $f cmp $g;          # OUTPUT: «Less␤»
    say $f.Str cmp $g.Str;  # OUTPUT: «More␤»

=end pod

# vim: expandtab shiftwidth=4 ft=perl6
