package sbt
sealed trait Result[+T]
{
def toEither: Either[Incomplete, T]
}
final case class Inc(cause: Incomplete) extends Result[Nothing]
{
def toEither: Either[Incomplete, Nothing] = Left(cause)
}
final case class Value[+T](value: T) extends Result[T]
{
def toEither: Either[Incomplete, T] = Right(value)
}
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
}
}
def tryValues[S](r: Seq[Result[Unit]], v: Result[S]): S =
{
r foreach tryValue[Unit]
tryValue[S](v)
}
implicit def fromEither[T](e: Either[Incomplete, T]): Result[T] = e match {
case Left(i) => Inc(i)
case Right(v) => Value(v)
}
}