# role Setty

Collection of distinct objects

```
role Setty does QuantHash { }
```

A role for collections which make sure that each element can only appear once. See Set and SetHash.

# Methods

## method grab

```
method grab($count = 1)
```

Removes and returns `$count`

elements chosen at random (without repetition) from the set.

If `*`

is passed as `$count`

, or `$count`

is greater than or equal to the size of the set, then all its elements are removed and returned in random order.

Only works on mutable sets; When used on an immutable set, it results in an exception.

## method grabpairs

```
method grabpairs($count = 1)
```

Removes `$count`

elements chosen at random (without repetition) from the set, and returns a list of `Pair`

objects whose keys are the grabbed elements and whose values are `True`

.

If `*`

is passed as `$count`

, or `$count`

is greater than or equal to the size of the set, then all its elements are removed and returned as `Pair`

s in the aforementioned way in random order.

Only works on mutable sets; When used on an immutable set, it results in an exception.

## method pick

```
multi method pick($count = 1)
```

Returns `$count`

elements chosen at random (without repetition) from the set.

If `*`

is passed as `$count`

, or `$count`

is greater than or equal to the size of the set, then all its elements are returned in random order.

## method roll

```
multi method roll($count = 1)
```

Returns a lazy list of `$count`

elements, each randomly selected from the set. Each random choice is made independently, like a separate die roll where each die face is a set element.

If `*`

is passed as `$count`

, the list is infinite.

## method keys

Defined as:

```
multi method keys(Setty:D:) returns Seq:D
```

Returns a Seq of all elements of the set.

```
my $s = Set.new(1, 2, 3);
say $s.keys; # (3 1 2)
```

## method values

Defined as:

```
multi method values(Setty:D:) returns Seq:D
```

Returns a Seq containing as many `True`

values as the set has elements.

```
my $s = Set.new(1, 2, 3);
say $s.values; # (True True True)
```

## method kv

Defined as:

```
multi method kv(Setty:D:) returns Seq:D
```

Returns a Seq of the set's elements and `True`

values interleaved.

```
my $s = Set.new(1, 2, 3);
say $s.kv; # (3 True 1 True 2 True)
```

## method elems

```
method elems(--> Int)
```

The number of elements of the set.

## method total

```
method total(--> Int)
```

The total of all the values of the `QuantHash`

object. For a `Setty`

object, this is just the number of elements.

## method ACCEPTS

```
method ACCEPTS($other)
```

Returns `True`

if `$other`

and `self`

contain all the same elements, and no others.

## method Bag

Defined as:

```
method Bag(Setty:D:) returns Bag:D
```

Returns a Bag containing the elements of the invocant.

```
my Bag $b = Set.new(1, 2, 3).Bag;
say $b; # bag(3, 1, 2)
```

## method BagHash

Defined as:

```
method BagHash(Setty:D:) returns BagHash:D
```

Returns a BagHash containing the elements of the invocant.

```
my BagHash $b = Set.new(1, 2, 3).BagHash;
say $b; # BagHash.new(3, 1, 2)
```

## method Bool

Defined as:

```
multi method Bool(Setty:D:) returns Bool:D
```

Returns `True`

if the invocant contains at least one element.

```
my $s1 = Set.new(1, 2, 3);
say $s1.Bool; # True
my $s2 = $s1 ∩ Set.new(4, 5); # set intersection operator
say $s2.Bool; # False
```