=begin pod

=TITLE class IntStr

=SUBTITLE Dual Value Integer and String

    class IntStr is Int 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>; say $f.WHAT; # (IntStr)

An C<IntStr> can be used interchangeably where one might use a L<Str|/type/Str> or an
L<Int|/type/Int> :

    my $f = <42>;
    my $i = $f + 1;
    my $s = $f ~ " and a bit";

=head1 Methods

=head2 method new

    method new(Int $i, Str $s)

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

    my $f = IntStr.new(42, "forty two");
    say +$f; # -> 42
    say ~$f; # -> "forty two"

=head2 method Numeric

    method Numeric

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

=head2 method Int

    method Int

Returns the integer value of the C<IntStr>.

=head2 method Str

Returns the string value of the C<IntStr>.

=head1 Operators

=head2 infix cmp

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

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

    my $f = IntStr.new(42, "smaller");
    my $g = IntStr.new(43, "larger");
    say $f cmp $g;          # Less
    say $f.Str cmp $g.Str;  # More

=end pod

# vim: expandtab shiftwidth=4 ft=perl6
