Background
It is quite convenient that case
statements can check that all values in the enum are covered, for example:
attack := enum:
Beam
Missile
GetDamage(Attack: attack):float=
case (Attack):
attack.Beam => 100.0
attack.Missile => 500.0
If I add a new value to the enum above, Verse will tell me that case needs to handle it.
Problem
However let’s say I want to iterate through all values:
for (Attack: array { attack.Beam, attack.Missile }):
SetupAttack(Attack)
in this case, if a new value is added to the original enum, it will not be covered in the iteration.
Proposal
Provide a built-in way to enumerate all values of an enum.
Order can match the order in code.
Some options:
# Option 1: Enumerate the type itself.
#
# Reads a bit awkwardly, but does feel consistent with Verse's design spirit, to the extent I understand https://simon.peytonjones.org/assets/pdfs/haskell-exchange-22.pdf (which is not much).
for (Attack: attack) { ... }
# Option 2: Enumerate through a helper method.
for (Attack: GetEnumElements(attack)) { ... }
# Option 3: Constrain array to require all enum values
AllAttacks := array<exhaustive> { attack.Beam, attack.Missile }
for (Attack: AllAttacks) { ... }