In role Buf§
See primary documentation in context for method subbuf-rw
method subbuf-rw($from = 0, $elems = self.elems - $from) is rw
A mutable version of subbuf
that returns a Proxy
functioning as a writable reference to a part of a buffer. Its first argument, $from
specifies the index in the buffer from which a substitution should occur, and its last argument, $elems
specifies how many elements are to be replaced.
For example, to replace one element at index 3 with two elements, 100
and 101
:
my Buf $bú .= new(0..5); $bú.subbuf-rw(3,1) = Buf.new(100, 101); say $bú.raku; # OUTPUT: «Buf.new(0,1,2,100,101,4,5)»
In the case the $elems
argument is not specified, the substitution happens at the specified index $from
removing all trailing elements:
my Buf $bú .= new(0..5); $bú.subbuf-rw(3) = Buf.new(200); say $bú.raku; # OUTPUT: «Buf.new(0,1,2,200)»
In the case the $from
argument is not specified, the substitution happens from the very beginning of the buffer:
my Buf $bú .= new(0..5); $bú.subbuf-rw = Buf.new(123, 123); say $bú.raku; # OUTPUT: «Buf.new(123, 123)»
In role Buf§
See primary documentation in context for routine subbuf-rw
multi subbuf-rw(Buf:D \b) is rw multi subbuf-rw(Buf:D \b, Int() $from) is rw multi subbuf-rw(Buf:D \b, $from, $elems) is rw
Returns a writable reference to a part of a buffer. Invokes the subbuf-rw
method on the specified Buf
:
my Buf $bú .= new(1,2,3); subbuf-rw($bú,2,1) = Buf.new(42); say $bú.raku; # OUTPUT: «Buf.new(1,2,42)»