2010-06-01 14:38:56 +02:00
|
|
|
/* sbt -- Simple Build Tool
|
|
|
|
|
* Copyright 2010 Mark Harrah
|
|
|
|
|
*/
|
|
|
|
|
package sbt
|
|
|
|
|
|
2010-06-07 14:53:21 +02:00
|
|
|
// used instead of Either[Incomplete, T] for type inference
|
|
|
|
|
|
|
|
|
|
/** Result of completely evaluating a task.*/
|
2010-06-01 14:38:56 +02:00
|
|
|
sealed trait Result[+T]
|
2010-08-30 15:10:25 +02:00
|
|
|
{
|
|
|
|
|
def toEither: Either[Incomplete, T]
|
|
|
|
|
}
|
2010-06-07 14:53:21 +02:00
|
|
|
/** Indicates the task did not complete normally and so it does not have a value.*/
|
|
|
|
|
final case class Inc(cause: Incomplete) extends Result[Nothing]
|
2010-08-30 15:10:25 +02:00
|
|
|
{
|
|
|
|
|
def toEither: Either[Incomplete, Nothing] = Left(cause)
|
|
|
|
|
}
|
2010-06-07 14:53:21 +02:00
|
|
|
/** Indicates the task completed normally and produced the given `value`.*/
|
|
|
|
|
final case class Value[+T](value: T) extends Result[T]
|
2010-08-30 15:10:25 +02:00
|
|
|
{
|
|
|
|
|
def toEither: Either[Incomplete, T] = Right(value)
|
|
|
|
|
}
|
2010-06-07 14:53:21 +02:00
|
|
|
|
|
|
|
|
object Result
|
|
|
|
|
{
|
|
|
|
|
type Id[X] = X
|
|
|
|
|
val tryValue = new (Result ~> Id) {
|
|
|
|
|
def apply[T](r: Result[T]): T =
|
|
|
|
|
r match {
|
|
|
|
|
case Value(v) => v
|
|
|
|
|
case Inc(i) => throw i
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|