4
4
5
5
= SUBTITLE Unordered collections of unique and weighted objects in Perl 6
6
6
7
- You might want to collect objects in a container but you do not care
8
- about the order of these objects. For such cases, Perl 6 provides the
7
+
8
+ In a nutshell, these classes hold, in general, unordered collections of
9
+ objects. Sets only consider if these objects are present or not, bags can
10
+ hold several objects of the same kind, and mixes also allow fractional (and
11
+ negative) weights. The regular versions are immutable, the I < Hash > versions
12
+ are mutable.
13
+
14
+ Let's elaborate on that. If you want to collect objects in a container but you
15
+ do not care about the order of these objects, Perl 6 provides the
9
16
I < unordered > collection types L < Set|/type/Set > ,
10
17
L < SetHash|/type/SetHash > , L < Bag|/type/Bag > , L < BagHash|/type/BagHash > ,
11
18
L < Mix|/type/Mix > , and L < MixHash|/type/MixHash > . Being unordered, these
12
19
containers can be more efficient than L < Lists|/type/List > for looking up
13
20
elements or dealing with repeated items.
14
21
15
- If you want to get the contained objects (elements) B < without
22
+ On the other hand, if you want to get the contained objects (elements) B < without
16
23
duplicates > and you only care I < whether > an element is in the collection
17
24
or not, you can use a L < Set|/type/Set > or L < SetHash|/type/SetHash > . If
18
25
you want to get rid of duplicates but still preserve order, take a look
@@ -33,6 +40,7 @@ The types L<Mix|/type/Mix> and L<MixHash|/type/MixHash> are similar
33
40
to L < Bag|/type/Bag > and L < BagHash|/type/BagHash > , but they also
34
41
allow B < fractional and negative weights > .
35
42
43
+
36
44
= begin comment
37
45
= defn Bag or BagHash
38
46
Collection of distinct objects mapped to integer weights
@@ -71,7 +79,7 @@ associated weights are the 'values':
71
79
72
80
= head1 Set/Bag operators
73
81
74
- There are several infixes devoted to performing common operations on
82
+ There are several infix operators devoted to performing common operations on
75
83
L < Set|/type/Set > , such as unions and set differences. Other operations
76
84
include boolean checks, like whether an object is an element of a
77
85
C < Set > , or whether one C < Set > is a subset of another C < Set > .
0 commit comments