Created
April 14, 2012 09:08
-
-
Save gakuzzzz/2383028 to your computer and use it in GitHub Desktop.
計算中と計算終了を表すコンテナ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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