my
An IterationBuffer
is used when the implementation of an Iterator
class needs a lightweight way to store/transmit values. It doesn't make Scalar
containers, and only supports mutation through the BIND-POS
method, only supports adding values with the push
and unshift
methods, supports merging of two IterationBuffer
objects with the append
and prepend
methods, and supports resetting with the clear
method.
It can be coerced into a List
, Slip
, or Seq
.
Values will be stored "as is", which means that Junctions will be stored as such and will not autothread.
As of release 2021.12 of the Rakudo compiler, the new
method also accepts an Iterable
as an optional argument which will be used to fill the IterationBuffer
.
Methods§
method push§
method push(IterationBuffer: Mu \value)
Adds the given value at the end of the IterationBuffer
and returns the given value.
method unshift§
method unshift(IterationBuffer: Mu \value)
Adds the given value at the beginning of the IterationBuffer
and returns the given value. Available as of the 2021.12 release of the Rakudo compiler.
method append§
method append(IterationBuffer: IterationBuffer --> IterationBuffer)
Adds the contents of the other IterationBuffer
at the end of the IterationBuffer
, and returns the updated invocant.
method prepend§
method prepend(IterationBuffer: IterationBuffer --> IterationBuffer)
Adds the contents of the other IterationBuffer
at the beginning of the IterationBuffer
, and returns the updated invocant. Available as of the 2021.12 release of the Rakudo compiler.
method clear§
method clear(IterationBuffer: --> Nil)
Resets the number of elements in the IterationBuffer
to zero, effectively removing all data from it, and returns Nil
.
method elems§
method elems(IterationBuffer: --> Int)
Returns the number of elements in the IterationBuffer
.
method AT-POS§
multi method AT-POS(IterationBuffer: int )multi method AT-POS(IterationBuffer: Int )
Returns the value at the given element position, or Mu
if the element position is beyond the length of the IterationBuffer
, or an error will be thrown indicating the index is out of bounds (for negative position values).
method BIND-POS§
multi method BIND-POS(IterationBuffer: int , Mu \value)multi method BIND-POS(IterationBuffer: Int , Mu \value)
Binds the given value at the given element position and returns it. The IterationBuffer
is automatically lengthened if the given element position is beyond the length of the IterationBuffer
. An error indicating the index is out of bounds will be thrown for negative position values.
method Slip§
method Slip(IterationBuffer: --> Slip)
Coerces the IterationBuffer
to a Slip
.
method List§
method List(IterationBuffer: --> List)
Coerces the IterationBuffer
to a List
.
method Seq§
method Seq(IterationBuffer: --> Seq)
Coerces the IterationBuffer
to a Seq
.
method raku§
method raku(IterationBuffer: --> Str)
Produces a representation of the IterationBuffer
as a List
postfixed with ".IterationBuffer" to make it different from an ordinary list. Does not roundtrip. Intended for debugging uses only, specifically for use with dd.