Created
December 14, 2011 11:59
-
-
Save makotan/1476310 to your computer and use it in GitHub Desktop.
Either[L,Either[L,R]]のように多段になる場合にRだけを取得する
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
def eith[R](arg: Either[Throwable, Any] ) : R = { | |
arg match { | |
case Left(e) => throw e | |
case Right(o:Either[Throwable, Any]) => eith(o) | |
case Right(o:R) => o | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
この定義だと、eith Stringのようにして呼び出すか、
val x: Int = eith(eitherObj)
のように、R の型をうまく推論できるパターンでないと、R = Nothingとして推論されてしまい不便なので、ちょっと改良版?を作ってみました。
https://gist.github.com/1476542