私はカスタムタイプ、Value
あります内蔵タイプ
sealed trait GetsValue[T] { def apply(record: T): Option[Value] }
object GetsValue {
trait GetsBooleanValue[T] extends GetsValue[T] { override def apply(record: T): Option[Value.BooleanValue] }
trait GetsLongValue[T] extends GetsValue[T] { override def apply(record: T): Option[Value.LongValue] }
}
:
trait Value
object Value {
case class BooleanValue(record: Boolean) extends Value
case class LongValue(record: Long) extends Value
}
そしてValue
を取得する方法を知っている特性は、いくつかの入力タイプT
を与え、GetsValue
と呼ばれます
GetsValueは封印されているため、ユーザーはGetsValue.GetsBooleanValue
またはGetsValue.GetsLongValue
にしか拡張されません。
trait Extractor[T] {
def title: String
def getsValue: GetsValue[T]
def relatedValue[U]: U = ??? // question below
}
私は何を達成したいことは以下の通りです: "!BOO"
getsValue
がGetsValue.GetsBooleanValue[_]
であれば、テキストでString
を返します(すなわちU
はタイプString
です)。
getsValue
場合は、その後(すなわち、U
タイプDouble
である)1.1の値でDouble
を返す、GetsValue.GetsLongValue[_]
あります。
getsValue
のタイプT
とは一致しません。私はそのタイプT
とは無関係にマッチしたいです。
意味が分かれば、タイプクラス/インプリシットを使用したいと思います。 Either
を使用することは私の選択肢ではありません。
私はそれがうまくいくとは思わないが、パスに依存する型を使用しても、ラップされたdouble/Stringを持つことができます。 –