Q:

Recommended way to transform map after using groupBy in Scala?

I have a Java enum being used from a dependency, and want to create a map from it.
Let's say the enum is called "SomeEnum1": 
BLUE(SomeEnum1.builder()
    .someOtherIdentifier("ABC")
    .someImportantField("DEF")), ...
RED( //etc 

I am able to use groupby and get a Map from the "someImportantField" value to a list of SomeEnum1:
SomeEnum1.values.groupBy(x => x.someImportantField)

But upon doing this, I get a Map[String, Array[SomeEnum1]] when what I want is a Map[String, Array[String]]. I've tried using:
SomeEnum1.values.groupBy(_.getSomeImportantField).mapValues(_.name)

But I get an error that name does not a member of Array[....SomeEnum1].
Is there some other way I can transform the resulting arrays to contain the enum names instead of the enum itself?

A:

You're missing a loop:
SomeEnum1.values.groupBy(_.getSomeImportantField).mapValues(_.map(_.name))

mapValues iterates over each Map value, which is an array of enums. For each of these arrays you want to convert each element to a String.

