This file contains hidden or 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
object RetryUtil { | |
import scala.util.control.Exception.allCatch | |
case class RetryResult[T](e: Either[List[Throwable], T]) { | |
def `catch`(f: List[Throwable] => T): T = e match { | |
case Right(r) => r | |
case Left(l) => f(l) | |
} | |
} |
This file contains hidden or 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 connect = { | |
log("connect") { // connect start | |
// ... 何かの処理 ... | |
log("login") { // connect : login start | |
// ... 何かの処理 ... | |
} // connect : login end | |
// ... 何かの処理 ... | |
} // connect end | |
} |
This file contains hidden or 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
implicit def l[A,B]: Either[A =:= A, A =:= B] = Left(=:=.tpEquals[A]) | |
implicit def r[A,B]: Either[B =:= A, B =:= B] = Right(=:=.tpEquals[B]) | |
def valueIsIntOrString[T](value: T)(implicit param: Either[T =:= String, T =:= Int]) = param match { | |
case Left(t2String) => | |
println("value is String") | |
println(t2String(value)) | |
case Right(t2Int) => | |
println("value is Int") |