Skip to content

Instantly share code, notes, and snippets.

@gakuzzzz
Created April 14, 2012 09:08
Show Gist options
  • Save gakuzzzz/2383028 to your computer and use it in GitHub Desktop.
Save gakuzzzz/2383028 to your computer and use it in GitHub Desktop.
計算中と計算終了を表すコンテナ
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