Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
計算中と計算終了を表すコンテナ
trait Container[+R, +C] {
def map[A](f: C => A): Container[R, A]
def flatMap[RR >: R, A](f: C => Container[RR, A]): Container[RR, A]
def get[RR >: R](implicit ev: C <%< RR): RR
}
case class Calculating[+R, +C](element: C) extends Container[R, C] {
def map[A](f: C => A): Container[R, A] = Calculating(f(element))
def flatMap[RR >: R, A](f: C => Container[RR, A]): Container[RR, A] = f(element)
def get[RR >: R](implicit ev: C <%< RR): RR = element
}
case class Result[+R](element: R) extends Container[R, Nothing] {
def map[A](f: Nothing => A): Container[R, A] = this
def flatMap[RR >: R, A](f: Nothing => Container[RR, A]): Container[RR, A] = this
def get[RR >: R](implicit ev: Nothing <%< RR): RR = element
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.