Given,
trait GetOrElseAble[Container[_]] {
def getOrElse[A](one : Container[A], two : A) : A
}
And,
implicit val optionGetOrElseAble = new GetOrElseAble[Option] {
override def getOrElse[A](one: Option[A], two: A): A = one.getOrElse(two)
}
And,
trait GetOrElseOp[A,F[_]] {
val evidence : GetOrElseAble[F]
val value : F[A]
def |(other : A) : A = evidence.getOrElse(value,other)
}
And finally the implicit def,
implicit def toGetOrElseOp[A,F[_]](f : F[A])(implicit e : GetOrElseAble[F]) = new GetOrElseOp[A,F] {
override val evidence = e
override val value = f
}
Following works:
toGetOrElseOp(None)(optionGetOrElseAble) | 100
However, None | 100
does not work.
According to my understanding, the implicit def
should have kicked in, converted None
to the type GetOrElseOp
and the above should have worked.
What am I missing? Thanks!