Is there an idiomatic way of generating something like a fromString
method on a sealed trait
for use with case classes
?
For example, something like:
sealed trait ExampleEnum {def id: Any}
final case class One(first: String) extends ExampleEnum{ override def id = first}
final case class Two(first: String, second: String) extends ExampleEnum { override def id = (first, second) }
Where should def fromString(s: String): ExampleEnum
exist? A companion object
for the sealed trait
? Something else? It feels like this "de-serialization" pattern would be something that exists or has a standard approach that would be found in existing packages.