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 - $fromis 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(100101);
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(123123);
say $b.raku;   # OUTPUT: «Buf.new(123, 123)␤»

role Buf

From Buf

(Buf) routine subbuf-rw

Declared as

multi sub subbuf-rw(Buf:D \bis rw
multi sub subbuf-rw(Buf:D \bInt() $fromis rw
multi sub subbuf-rw(Buf:D \b$from$elemsis 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)␤»