|
| 1 | +=begin pod :kind("Type") :subkind("class") :category("composite") |
| 2 | + |
| 3 | +=TITLE class IterationBuffer |
| 4 | + |
| 5 | +=SUBTITLE Lowlevel storage of positional values |
| 6 | + |
| 7 | +=for code |
| 8 | +my class IterationBuffer { } |
| 9 | + |
| 10 | +An C<IterationBuffer> is used when the implementation of an C<Iterator> |
| 11 | +class needs a lightweight way to store/transmit values. It doesn't make |
| 12 | +C<Scalar> containers, and only supports mutation through the C<BIND-POS> |
| 13 | +method, only supports adding values with the C<push> and C<unshift> |
| 14 | +methods, supports merging of two C<IterationBuffer> objects with the |
| 15 | +C<append> and C<prepend> methods, and supports resetting with the |
| 16 | +C<clear> method. |
| 17 | + |
| 18 | +It can be coerced into a C<List>, C<Slip>, C<List> or C<Seq>. |
| 19 | + |
| 20 | +Values will be stored "as is", which means that L<Junctions|/type/Junction> |
| 21 | +will be stored as such and will B<not> L<autothread|/language/glossary#Autothreading>. |
| 22 | + |
| 23 | +The C<new> method accepts an L<Iterable|/type/Iterable> as an optional |
| 24 | +argument which, when specified, will be used to fill the C<IterationBuffer>. |
| 25 | + |
| 26 | +=head1 Methods |
| 27 | + |
| 28 | +=head2 method push |
| 29 | + |
| 30 | + method push(IterationBuffer:D: Mu \value) |
| 31 | + |
| 32 | +Adds the given value at the end of the C<IterationBuffer>. |
| 33 | + |
| 34 | +=head2 method unshift |
| 35 | + |
| 36 | + method unshift(IterationBuffer:D: Mu \value) |
| 37 | + |
| 38 | +Adds the given value at the beginning of the C<IterationBuffer>. |
| 39 | + |
| 40 | +=head2 method append |
| 41 | + |
| 42 | + method append(IterationBuffer:D: IterationBuffer:D $other) |
| 43 | + |
| 44 | +Adds the contents of the other C<IterationBuffer> at the end of |
| 45 | +the C<IterationBuffer>. |
| 46 | + |
| 47 | +=head2 method prepend |
| 48 | + |
| 49 | + method prepend(IterationBuffer:D: IterationBuffer:D $other) |
| 50 | + |
| 51 | +Adds the contents of the other C<IterationBuffer> at the beginning |
| 52 | +of the C<IterationBuffer>. |
| 53 | + |
| 54 | +=head2 method clear |
| 55 | + |
| 56 | + method clear(IterationBuffer:D:) |
| 57 | + |
| 58 | +Resets the number of elements in the C<IterationBuffer> to zero, |
| 59 | +effectively removing all data from it. |
| 60 | + |
| 61 | +=head2 method elems |
| 62 | + |
| 63 | + method elems(IterationBuffer:D:) |
| 64 | + |
| 65 | +Returns the number of elements in the C<IterationBuffer>. |
| 66 | + |
| 67 | +=head2 method AT-POS |
| 68 | + |
| 69 | + multi method AT-POS(IterationBuffer:D: int $pos) |
| 70 | + multi method AT-POS(IterationBuffer:D: Int:D $pos) |
| 71 | + |
| 72 | +Returns the value at the given element position, or C<Mu> if |
| 73 | +the element position is beyond the length of the C<IterationBuffer>, |
| 74 | +or an error will be thrown indicating the index is out of bounds |
| 75 | +(for negative position values). |
| 76 | + |
| 77 | +=head2 method BIND-POS |
| 78 | + |
| 79 | + multi method BIND-POS(IterationBuffer:D: int $pos, Mu \value) |
| 80 | + multi method BIND-POS(IterationBuffer:D: Int:D $pos, Mu \value) |
| 81 | + |
| 82 | +Binds the given value at the given element position and returns it. |
| 83 | +The C<IterationBuffer> is automatically lengthened if the given |
| 84 | +element position is beyond the length of the C<IterationBuffer>. |
| 85 | +An error indicating the index is out of bounds will be thrown for |
| 86 | +negative position values. |
| 87 | + |
| 88 | +=head2 method Slip |
| 89 | + |
| 90 | + method Slip(IterationBuffer:D:) |
| 91 | + |
| 92 | +Coerces the C<IterationBuffer> to a L<Slip|/type/Slip>. |
| 93 | + |
| 94 | +=head2 method List |
| 95 | + |
| 96 | + method List(IterationBuffer:D:) |
| 97 | + |
| 98 | +Coerces the C<IterationBuffer> to a L<List|/type/List>. |
| 99 | + |
| 100 | +=head2 method Seq |
| 101 | + |
| 102 | + method Seq(IterationBuffer:D:) |
| 103 | + |
| 104 | +Coerces the C<IterationBuffer> to a L<Seq|/type/Seq>. |
| 105 | + |
| 106 | +=head2 method raku |
| 107 | + |
| 108 | + method raku(IterationBuffer:D:) |
| 109 | + |
| 110 | +Produces a representation of the C<IterationBuffer> as a C<List> |
| 111 | +postfixed with ".IterationBuffer" to make it different from an |
| 112 | +ordinary list. Does B<not> roundtrip. Intended for debugging |
| 113 | +uses only, specifically for use with L<dd|/programs/01-debugging#Dumper_function_(dd)>. |
| 114 | + |
| 115 | +=end pod |
0 commit comments