25 lines
572 B
Scala
25 lines
572 B
Scala
package green.thisfieldwas.embracingnondeterminism.extractables.seq
|
|
|
|
sealed trait Either[+X, +A] extends Extractable[A] {
|
|
|
|
def left: X
|
|
|
|
def right: A
|
|
|
|
// satisfies non-empty Seq if present
|
|
// satisfies fault if void
|
|
def extract: Seq[A] = Seq(right)
|
|
|
|
def isExtractable: Boolean = this.isInstanceOf[Right[X, A]]
|
|
}
|
|
|
|
case class Left[+X, +A](left: X) extends Either[X, A] {
|
|
|
|
def right: A = throw new NoSuchElementException("Left.right")
|
|
}
|
|
|
|
case class Right[+X, +A](right: A) extends Either[X, A] {
|
|
|
|
def left: X = throw new NoSuchElementException("Right.left")
|
|
}
|