Skip to content

Instantly share code, notes, and snippets.

@ogatatsu
ogatatsu / readme.md
Created June 27, 2012 11:10 — forked from j5ik2o/gist:2996293
リトライハンドラー 魔改造
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)
}
}
@ogatatsu
ogatatsu / gist:1518754
Created December 25, 2011 05:10 — forked from j5ik2o/gist:1518723
こんな構文で階層型のログ出力をしたい
def connect = {
log("connect") { // connect start
// ... 何かの処理 ...
log("login") { // connect : login start
// ... 何かの処理 ...
} // connect : login end
// ... 何かの処理 ...
} // connect end
}
@ogatatsu
ogatatsu / Or.scala
Created January 4, 2011 12:22 — forked from kmizu/Or.scala
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")