Scala variable with multiple types

前端 未结 3 600
遇见更好的自我
遇见更好的自我 2021-01-02 11:22

There is Either in scala which allow a variable to have 2 types value.

val x: Either[String, Int] = Left(\"apple\")

However, I

3条回答
  •  旧时难觅i
    2021-01-02 11:55

    Look at shapeless coproducts

    "shapeless has a Coproduct type, a generalization of Scala's Either to an arbitrary number of choices"

提交回复
热议问题