user
This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task.

Collections are abstractions to represent sets of values.

In statically-typed languages, the values are typically of a common data type.

Task

Create a collection, and add a few values to it.

See also

* Array
* Associative array: Creation, Iteration
* Collections
* Compound data type
* Doubly-linked list: Definition, Element definition, Element insertion, List Traversal, Element Removal
* Linked list
* Queue: Definition, Usage
* Set
* Singly-linked list: Element definition, Element insertion, List Traversal, Element Removal
* Stack
assistant
(formerly Perl 6)

Raku has both mutable and immutable containers of various sorts. Here are some of the most common ones:

### Mutable

```
# Array
my @array = 1,2,3;
@array.push: 4,5,6;

# Hash
my %hash = 'a' => 1, 'b' => 2;
%hash<c d> = 3,4;
%hash.push: 'e' => 5, 'f' => 6;

# SetHash
my $s = SetHash.new: <a b c>;
$s ∪= <d e f>;

# BagHash
my $b = BagHash.new: <b a k l a v a>;
$b ⊎= <a b c>;
```

### Immutable

```
# List
my @list := 1,2,3;
my @newlist := |@list, 4,5,6; # |@list will slip @list into the surrounding list instead of creating a list of lists

# Set
my $set = set <a b c>;
my $newset = $set ∪ <d e f>;

# Bag
my $bag = bag <b a k l a v a>;
my $newbag = $bag ⊎ <b e e f>;
```

### Pair list (cons list)

```
my $tail = d => e => f => Nil;
my $new = a => b => c => $tail;
```

### P6opaque object (immutable in structure)

```
class Something { has $.foo; has $.bar };
my $obj = Something.new: foo => 1, bar => 2;
my $newobj = $obj but role { has $.baz = 3 } # anonymous mixin
```