method freeze

Documentation for method freeze assembled from the following types:

class Pair

From Pair

(Pair) method freeze

Defined as:

method freeze(Pair:D:)

Makes the value of the Pair read-only, by removing it from its Scalar container, and returns it.

my $str = "apple";
my $p = Pair.new('key'$str);
$p.value = "orange";              # this works as expected 
$p.say;                           # OUTPUT: «key => orange␤» 
$p.freeze.say;                    # OUTPUT: «orange␤» 
$p.value = "a new apple";         # Fails 
CATCH { default { put .^name''.Str } };
# OUTPUT: «X::Assignment::RO: Cannot modify an immutable Str (apple)␤»

NOTE: this method is deprecated as of 6.d language version. Instead, create a new Pair, with a decontainerized key/value.

$p.=Map.=head.say;                                    # OUTPUT: «orange␤»