BrowserREPL-button-tip-on BrowserREPL-button-tip-off

EditButtonTip 2023-12-24

class StrDistance

Contains the result of a string transformation.

StrDistance objects are used to represent the return of the string transformation operator.

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

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

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

Methods§

method before§

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

say $str-dist.before; # OUTPUT: «fold␤»
Code

method after§

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

say $str-dist.after;  # OUTPUT: «fnew␤»
Code

method Bool§

Returns True if before is different from after.

method Numeric§

Returns the distance as a number.

method Int§

multi method Int(StrDistance:D:)
Code

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

method Str§

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

Returns an after string value.

my $str-dist = ($str ~~ tr/old/new/);
say $str-dist.Str; # OUTPUT: «fnew␤»
say ~$str-dist;    # OUTPUT: «fnew␤»
Code

Class relation diagram§

Rakudo Type Relation for StrDistance StrDistance StrDistance Cool Cool StrDistance->Cool is