Documentation for routine subbuf-rw
assembled from the following pages:
Role: Buf §
From Buf
(Buf) method subbuf-rw §
method subbuf-rw( = 0, = self.elems - ) 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 .= new(0..5);.subbuf-rw(3,1) = Buf.new(100, 101);say .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 .= new(0..5);.subbuf-rw(3) = Buf.new(200);say .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 .= new(0..5);.subbuf-rw = Buf.new(123, 123);say .raku; # OUTPUT: «Buf.new(123, 123)»
Role: Buf §
From Buf
(Buf) routine subbuf-rw §
Declared as
multi sub subbuf-rw(Buf \b) is rwmulti sub subbuf-rw(Buf \b, Int() ) is rwmulti sub subbuf-rw(Buf \b, , ) is rw
Returns a writable reference to a part of a buffer. Invokes the subbuf-rw
method on the specified Buf
:
my Buf .= new(1,2,3);subbuf-rw(,2,1) = Buf.new(42);say .raku; # OUTPUT: «Buf.new(1,2,42)»