I have to enums in two different proto files.
enum Some {
OPTIONA = 0;
OPTIONB = 1;
OPTIONC = 2;
}
enum SomeOther {
OPTIONA = 0;
OPTIONB = 1;
OPTIONC = 2;
}
They autogenerate into this in one file:
sealed abstract class Some(val value: _root_.scala.Int) extends _root_.scalapb.GeneratedEnum {}
object Some extends _root_.scalapb.GeneratedEnumCompanion[Some] {}
and this in another
sealed abstract class SomeOther(val value: _root_.scala.Int) extends _root_.scalapb.GeneratedEnum {...}
object SomeOther extends _root_.scalapb.GeneratedEnumCompanion[SomeOther] {...}
I would like to be able to convert Some to SomeOther or viceversa seamlessly without having to pattern match.
I really like chimney's expression something like:
Some.transformInto[SomeOther]
But it doesn't work as the chimney library errors out with the types being ambiguous
I tried to make an implicit class like so:
implicit class EnumToEnum[From <: GeneratedEnum](enum : GeneratedEnumCompanion[From]) {
def transformTo[To <: GeneratedEnum](err : Error): Either[Error, GeneratedEnumCompanion[To]] {
GeneratedEnumCompanion[To].fromValue(enum.value)
???
}
}
However I can't quite do that because GeneratedEnumCompanion and GeneratedEnum are traits.
So is there a way to convert seamlessly between proto enums with chimney and if not how can I write my own generic method?