Scala collation / comparison of listings

I have an enumeration that I want to use in pattern matches as an actor. I do not get what I expect, and now I suspect that I am missing something simple.

My listing

object Ops extends Enumeration {
  val Create = Value("create")
  val Delete = Value("delete")
}

Then I create Ops from the line:

val op = Ops.valueOf("create")

Inside my match I have:

case (Ops.Create, ...)

But Ops.Create is not like ops.valueOf ("create")

The first is just the "creation" of the atom, and later, Some (create)

I hope this is enough for someone to tell me that I am missing ...

thank

+5
source share
3 answers

If you are just trying to get a copy Create, you should refer to it directly in your code:

val op = Ops.Create

, , valueOf Option:

val op1 = Ops.valueOf("create")  // Some(Ops.Create)
val op2 = Ops.valueOf("delete")  // Some(Ops.Delete)
val op3 = Ops.valueOf("aljeaw")  // None

, , Option[Ops.Value] :

case(Some(Ops.Create),...)

.

+7

Enumeration.valueOf None Some, , . , Ops.valueOf("blah") None, .

, case case object Enumeration ( ).

+1

, get get Some, , . .

ops.valueOf("create").get == Ops.Create

, , .

-1

All Articles