routine subbuf-rw
Documentation for routine subbuf-rw
assembled from the following types:
role Buf
From Buf
(Buf) 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)»
role Buf
From Buf
(Buf) routine subbuf-rw
Declared as
multi sub subbuf-rw(Buf:D \b) is rw multi sub subbuf-rw(Buf:D \b, Int() $from) is rw multi sub 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)»