☺唐鳳☻
and 1 contributors

# parsefail :(

sub ∅ returns Set is export { set(); }

NAME

Set - Sets for Perl 6

SYNOPSIS

  use Set;

  my $set = set 23, 42, $some_object;

  say "42 is in the set" if $set.includes(42);
  say "The set contains {$set.size} items";

  $set.insert(13);
  $set.remove(23);

  my @members = $set.members;

  # Set arithmetic with arrays
  say ~([1,2,3] +# [1,2,6])    # 1 2 3 6  (in no particular order)
  say ~([1,2,3] -# [1,2,6])    # 3        (in no particular order)
  say ~([1,2,3] *# [1,2,6])    # 1 2      (in no particular order)
  say ~([1,2,3] %# [1,2,6])    # 3 6      (in no particular order)

CONSTRUCTORS

set(...)

Returns a new set containing all parameters.

Set.new()

Returns a new, empty set.

METHODS

$set.insert(...)

Inserts the specifiend items into the set. Returns the number of items inserted.

It is not fatal to insert an item which is already inserted.

$set.remove(...)

Removes the specified items from the set. Returns the number of items removed.

It is not fatal to remove an item which is not in the set.

$set.includes(...), $set.has(...)

Returns true if all given items are in the set. has is an alias for includes.

$set.member($item)

Returns the specified item if it's in the set.

$set.size(), $set.count()

Returns the number of elements in the set. count is an alias for size.

$set.invert(...)

Removes the given items if they are already in the set, or inserts the items if they're not in the set.

Returns the number of items removed.

$set.clear()

Clears the set.

COMPARISION METHODS

$set1.equal($set2)

Returns true if $set1 equals $set2, i.e. if $set1 contains all the items of $set2 and $set1 and $set2 have the same size.

$set1.not_equal($set2)

Returns true if $set1 does not equal $set2.

$set1.subset($set2)

Returns true if $set1 is a subset of $set2.

$set1.superset($set2)

Returns true if $set1 is a superset of $set2.

$set1.proper_subset($set2), $set1.proper_superset($set2)

Returns true if $set1 is a proper subset (superset) of $set2, i.e. if $set1 has at least one element less (more) than $set2.

$set1.union($set2)

Returns a new set containing all the elements of $set1 and $set2

$set1.intersection($set2)

Returns a new set containing all the elements of $set1 which are in $set2, too.

$set1.difference($set2)

Returns a new set containing all the elements of $set1 which are not in $set2.

$set1.symmetric_difference($set2)

XXX

BUGS

Currently, no operators are overloaded. This will change as soon Pugs supports overload operators.

AUTHORS

Sam "mugwump" Vilain (Code)

Ingo "iblech" Blechschmidt (Documentation)

Stevan "stevan" Little (misc. ugly hacks to make things work for now)

SEE ALSO

You might want to read the tests of Set.

1 POD Error

The following errors were encountered while parsing the POD:

Around line 16:

Non-ASCII character seen before =encoding in '∅'. Assuming UTF-8