Thursday, 15 March 2012

reflection - Getting all enum-y case object values in Scala -


itemprop = "text">

In Scala, enums are a disputed area and many people (including themselves), instead of matter matter Use compared to a library-based calculation. It's great, except that it does not get a list of all the possible values, which sometimes needs to be done. I have maintained such lists manually ( allKeys ), but this is tedious and error prone.

The question is: How can Scala 2.11 or reflection be used, such a list?

One of two ways will work:

  • Obtaining all the derivative examples of a sealed code
  • Note: Whatever I see in it seems promising. But this is redundancy - should it be about one-liner to get the same?

    Below is an examination for how can I implement the allOf function?

      Class Manifest Tools Test Unit (behavior of "Manfight Tools") {Seal Class Mynem Object Mynem {Case Object A Merian Came May Extend Case B: MyEnum Case Object C Spreads MyEnum Val x = 10 // def f (x: int) = x // should not be listed} def allOf [T]: Seq [T] = {...} it "to index the 'case object' of members of an object Should be enabled in "Val Tmp: Seq [MyEnum] = allOf [MyEnum] should include the par value in TMP (List (MyEnum.A, MyEnum.B, MyEnum.C)}}}  

    I have tried to get this information from Scala documentation, but when it comes to reflection So things are really abstract. I believe that the above is required (should be) covered by Scala 2.11.

    Reference:

itemprop = "text"

/ Html>

No comments:

Post a Comment