In Nil§
See primary documentation in context for method append
method append(*@)
Warns the user that they tried to append onto a Nil
(or derived type object).
In Hash§
See primary documentation in context for method append
method append(+)
Append the provided Pairs or even sized list to the Hash. If a key already exists, turn the existing value into an Array
and push new value onto that Array
. Please note that you can't mix even sized lists and lists of Pairs. Also, bare Pair
s or colon pairs will be treated as named arguments to .append
.
my = a => 1;.append('b', 2, 'c', 3);.append( %(d => 4) );say ;# OUTPUT: «{a => 1, b => 2, c => 3, d => 4}».append('a', 2);# OUTPUT: «{a => [1 2], b => 2, c => 3, d => 4}»
Note: Compared to push
, append
will slip
in the given value, whereas push
will add it as is:
my = :a[42, ]; .append: "a" => <a b c a>;say ; # OUTPUT: «{a => [42 a b c a]}»my = :a[42, ]; .push: "a" => <a b c a>;say ; # OUTPUT: «{a => [42 (a b c a)]}»
In Independent routines§
See primary documentation in context for sub append
multi append(\a, ** is raw)multi append(\a, \b)
Calls method append
on the first argument, passing the remaining arguments. Method append
is supposed to add the provided values to the end of the collection or parts thereof. Unlike method push
, method append
should follow the single argument rule. So if you want to implement a conforming method append
for a new collection type, it should behave as if its signature was just:
multi method append(::?CLASS: +values --> ::?CLASS)
Similar to routine push
, you may need to add a multi method if you want to support autovivification:
multi method append(::?CLASS: +values --> ::?CLASS)
The subroutine form of append
can be helpful when appending to the values of a Hash
. Whereas method append
will silently ignore literal pairs that are interpreted as named arguments, the subroutine will throw:
my = i => 0;append , i => (1, 42);CATCH ;# OUTPUT: «Unexpected named argument 'i' passed»
In Array§
See primary documentation in context for method append
multi method append(Array: ** is raw --> Array)multi method append(Array: \arg --> Array)
Adds the provided values to the end of the array and returns the modified array, or throws if the invocant array or an argument that requires flattening is lazy.
In contrast with method push, method append
adheres to the single argument rule and is probably best thought of as:
multi method append(Array: +values --> Array)
This means that if you pass a single argument that is a non-itemized Iterable
, append
will try to flatten it.
For example:
my = <a b c>;my = <d e f>;.append: ;say .elems; # OUTPUT: «6»say ; # OUTPUT: «[a b c d e f]»
In role Buf§
See primary documentation in context for method append
method append( )
Appends to the end of the buffer.
my = Buf.new( 1, 1, 2, 3, 5 );.append(9, 8, 7, 6);say .raku; # OUTPUT: «Buf.new(1,1,2,3,5,9,8,7,6)»
In Any§
See primary documentation in context for method append
multi method append(Any \SELF: |values)
In the case the instance is not a positional-thing, it instantiates it as a new Array
, otherwise clone the current instance. After that, it appends the values passed as arguments to the array obtained calling Array.append
on it.
my ;say .append; # OUTPUT: «[]»my ;say .append((1,2,3)); # OUTPUT: «[1 2 3]»
In IterationBuffer§
See primary documentation in context for 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.