aboutsummaryrefslogtreecommitdiff
path: root/tests/pos/i1790.scala
blob: 7535255f9edc40f6df4e6ae7063ac9f882714cb5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import scala.util.control.NonFatal

class Try[+T] {
  def transform[U](s: T => Try[U], f: Throwable => Try[U]): Try[U] =
    try this match {
      case Success(v) => s(v)
      case Failure(e) => f(e)
    } catch {
      case NonFatal(e) => Failure(e)
    }
}
final case class Success[+T](value: T) extends Try[T]
final case class Failure[+T](exception: Throwable) extends Try[T] {
  def get: T = throw exception
}