I'm trying to define an additional method on Scala's Try via implicit conversions. Here's my isolated, reproducible example--
import scala.util.Try
object App {
def main(args: Array[String]): Unit = {
val t = Try(2)
t.getOrThrow()
}
}
trait TrySyntax {
implicit final def trySyntax[A](t: Try[A]): TryOps[A] = new TryOps(t)
}
final class TryOps[A](val t: Try[A]) extends AnyVal {
def getOrThrow(): A = t.getOrElse(throw t.failed.get)
}
I'm running into the following compile error.
error: value getOrThrow is not a member of scala.util.Try[Int]
t.getOrThrow(
Does anyone know what I'm doing wrong? The explicit conversion--
trySyntax(t).getOrThrow
works fine. I've tried importing scala.languageFeatures.implicitConversions but didn't help. I also originally had the implicit conversion in its own package that was imported as import mypackage._
but that yielded the same result.