=begin pod :kind("Type") :subkind("class") :category("basic")

=TITLE class StrDistance

=SUBTITLE Contains the result of a string transformation.

C<StrDistance> objects are used to represent the return of the
L<string transformation|/syntax/tr$SOLIDUS$SOLIDUS$SOLIDUS> operator.

    say (($ = "fold") ~~ tr/old/new/).^name;  # OUTPUT: «StrDistance␤»

A C<StrDistance> object will stringify to the resulting string after the
transformation, and will numify to the distance between the two strings.

=begin code
my $str = "fold";
my $str-dist = ($str ~~ tr/old/new/);
say ~$str-dist;  # OUTPUT: «fnew␤»
say +$str-dist;  # OUTPUT: «3␤»
=end code

=head1 Methods

=head2 method before

This is actually a class attribute, and called as a method returns the string
before the transformation:

=for code :preamble<my $str = "fold"; my $str-dist = ($str ~~ tr/old/new/); >
say $str-dist.before; # OUTPUT: «fold␤»

=head2 method after

Also a class attribute, returns the string after the transformation:

=for code :preamble<my $str = "fold"; my $str-dist = ($str ~~ tr/old/new/); >
say $str-dist.after;  # OUTPUT: «fnew␤»

=head2 method Bool

Returns C<True> if C<before> is different from C<after>.

=head2 method Numeric

Returns the distance as a number.

=head2 method Int

Defined as:

    multi method Int(StrDistance:D:)

Returns the distance between the string before and after the transformation.

=head2 method Str

Defined as:

    multi method Str(StrDistance:D: --> Str)

Returns an C<after> string value.

    =begin code :preamble<my $str = "fold">
    my $str-dist = ($str ~~ tr/old/new/);
    say $str-dist.Str; # OUTPUT: «fnew␤»
    say ~$str-dist;    # OUTPUT: «fnew␤»
    =end code

=end pod

# vim: expandtab softtabstop=4 shiftwidth=4 ft=perl6
