Skip to content

Commit

Permalink
Correct statement re: cause of unordered iteration
Browse files Browse the repository at this point in the history
My previous commit stated that `enum`s provide unordered iteration because they 
_are_ `Map`s.  That is incorrect.  `enum`s provide unordered iteration because the
relevant iteration methods _create_ a corresponding `Map` to iterate over.

This commit corrects that misstatement.
  • Loading branch information
codesections authored and JJ committed Oct 16, 2021
1 parent 14c834c commit 2a1c378
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions doc/Language/typesystem.pod6
Original file line number Diff line number Diff line change
Expand Up @@ -791,9 +791,13 @@ the keys.
# OUTPUT: «(E::one E::two)␤» or «(E::two E::one)␤»
Note that, as the output above indicates, the iteration order of enums
is not guaranteed. This is because enums are C<Map>s. If you need
to iterate an enum in order, you may do so by sorting on its C<value>,
for example with C<E.enums.sort(*.value)>
is not guaranteed. This is because the methods that "iterate over" an
enum do not iterate I<directly> on the enum (which, after all, is not
iterable). Instead, these iteration methods create a C<Map> with the
same keys and values as the enum. Because C<Map>s provide only unordered,
iteration the iteration methods on an enum do as well. If you need to
iterate an enum in order, you can sort on its C<value>, for example
with C<E.enums.sort(*.value)>.
With the use of B<()> parentheses, an enum can be defined using any
arbitrary dynamically defined list. The list should consist of Pair
Expand Down

0 comments on commit 2a1c378

Please sign in to comment.