class IterationBuffer

Low level storage of positional values
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.

See Also

class Array

Sequence of itemized values

class Bag

Immutable collection of distinct objects with integer weights

class BagHash

Mutable collection of distinct objects with integer weights

class Capture

Argument list suitable for passing to a Signature

class Hash

Mapping from strings to itemized values

class List

Sequence of values

class Map

Immutable mapping from strings to values

class Mix

Immutable collection of distinct objects with Real weights

class MixHash

Mutable collection of distinct objects with Real weights

class NFC

Codepoint string in Normal Form C (composed)

class NFD

Codepoint string in Normal Form D (decomposed)

class NFKC

Codepoint string in Normal Form KC (compatibility composed)

class NFKD

Codepoint string in Normal Form KD (compatibility decomposed)

class Pair

Key/value pair

class PseudoStash

Stash type for pseudo-packages

class Range

Interval of ordered values

class Seq

An iterable, potentially lazy sequence of values

class Set

Immutable collection of distinct objects

class SetHash

Mutable collection of distinct objects

class Slip

A kind of List that automatically flattens into an outer container

class Stash

Table for "our"-scoped symbols

class Uni

A string of Unicode codepoints

class utf8

Mutable uint8 buffer for utf8 binary data

The Camelia image is copyright 2009 by Larry Wall. "Raku" is trademark of the Yet Another Society. All rights reserved.