freeze
ErrorsCollection

freeze

Synthesised documentation from type/Pair

From type/Pair

See Original text in context

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␤»