I’m new to Scala and trying to use Scala 3 enums as ADTs, and I have a collection I’m trying to “reduce” down in the following way:
enum Stats:
case MaximumHealth(val x: Float)
case HealthRegen(val x: Float)
def combineStats: Array[Stats] =
val startWith = Array(Stats.MaximumHealth(20), Stats.MaximumHealth(10), Stats.HealthRegen(5))
// how can I iterate/recurse over 'startWith' and "combine" multiple stats
// (such as MaximumHealth) entries into one?
// (ie, producing endWith below)?
val endWith = Array(Stats.MaximumHealth(30), Stats.HealthRegen(5))
endWith
How can I do this? GroupBy is often suggested but I don’t know how to group by just the enum case without the values of the parameters making Stats.MaximumHealth(20) and Stats.MaximumHealth(10) different groups.