sealerate icon indicating copy to clipboard operation
sealerate copied to clipboard

Set of java.lang.Class extending sealed trait

Open firehooper opened this issue 8 years ago • 4 comments

Not sure if this is in the scope of this library, but would it be possible to get a Set of java.lang.Class extending the sealed trait

firehooper avatar Feb 23 '17 20:02 firehooper

Do you mean like values.map(_.getClass)?

mrvisser avatar Feb 24 '17 08:02 mrvisser

Sorry I should have been more specific. the Set[java.lang.Class] would include case classes which are currently errored by values and filtered by collect. Something like caseClassValues: Set[java.lang.Class]

firehooper avatar Feb 24 '17 18:02 firehooper

Thanks for the clarification. Does this rough example reflect more of what you'd want?

sealed trait Option[+A]
object Option {
  case object None extends Option[Nothing]
  final case class Some[A](a: A) extends Option[A]

  def classes: Set[java.lang.Class[Option[_]]] = sealerate.classes[Option[_]]
}

Option.classes.map(_.getName).foreach(println)

// Results in:
// None
// Some

If so, can you give a code sample that reflects a non-contrived use-case for it?

mrvisser avatar Feb 25 '17 09:02 mrvisser

Yes that is exactly it. One use case is for validating all implementations of a trait are in application.conf for akka.actor.serialization-bindings and generate a diff for errors. Maybe next would be reading the .conf in a macro also or update the .conf within a macro. Currently validating at runtime. I understand these other macros might be outside the scope of the library since it does not currently depend on Typesafe Config, but once I read up and practice more with Scala macros I can contribute a PR.

firehooper avatar Feb 26 '17 20:02 firehooper