Skip to content

Commit

Permalink
Clarify that enum iteration is unordered
Browse files Browse the repository at this point in the history
Because enums are Maps, they do not iterate in any defined order.
But the docs didn't mention this, and provided an example that suggested
ordered iteration.  This commit adds a note to that effect and updates the 
example
  • Loading branch information
codesections authored and JJ committed Oct 16, 2021
1 parent 52ca420 commit 14c834c
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion doc/Language/typesystem.pod6
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,12 @@ the keys.
enum E <one two>;
my @keys = E::.values;
say @keys.map: *.raku;
# OUTPUT: «(E::one E::two)␤»
# 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)>
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 14c834c

Please sign in to comment.