my class IterationBuffer { }

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:D: Mu \value)

Adds the given value at the end of the IterationBuffer and returns the given value.

method unshift§

method unshift(IterationBuffer:D: 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:D: IterationBuffer:D $other --> IterationBuffer:D)

Adds the contents of the other IterationBuffer at the end of the IterationBuffer, and returns the updated invocant.

method prepend§

method prepend(IterationBuffer:D: IterationBuffer:D $other --> IterationBuffer:D)

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:D: --> 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:D: --> Int:D)

Returns the number of elements in the IterationBuffer.

method AT-POS§

multi method AT-POS(IterationBuffer:D: int   $pos)
multi method AT-POS(IterationBuffer:D: Int:D $pos)

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:D: int   $pos, Mu \value)
multi method BIND-POS(IterationBuffer:D: Int:D $pos, 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:D: --> Slip:D)

Coerces the IterationBuffer to a Slip.

method List§

method List(IterationBuffer:D: --> List:D)

Coerces the IterationBuffer to a List.

method Seq§

method Seq(IterationBuffer:D: --> Seq:D)

Coerces the IterationBuffer to a Seq.

method raku§

method raku(IterationBuffer:D: --> 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.