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") |
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
| /* | |
| import scala.collection.JavaConversions.JMapWrapperLike | |
| import scala.collection.generic.{SortedMapFactory, CanBuildFrom} | |
| import scala.collection | |
| class TreeMap[A, B](implicit val ordering: Ordering[A]) | |
| extends JMapWrapperLike[A, B, TreeMap[A, B]] | |
| with collection.SortedMap[A, B] | |
| with collection.SortedMapLike[A, B, TreeMap[A, B]] { | |
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
| import java.io._ | |
| import java.net._ | |
| import org.mozilla.javascript._ | |
| class CoffeeScript private(reader: Reader) { | |
| private val _compile = { | |
| val cx = Context.enter() | |
| //generated bytecode for method exceeds 64K limit.回避 |
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
| abstract class LangConverter { | |
| val `0`: String | |
| val `1`: String | |
| val sep: String | |
| private def binaryStringToLang(s: String): String = { | |
| s.map { | |
| case '0' => `0` | |
| case '1' => `1` |
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
| class RichEither[A](e: Either[Throwable, A]) { | |
| def success: A = e match { | |
| case Right(r) => r | |
| case Left(l) => throw l | |
| } | |
| } | |
| implicit def eitherWrapper[A](e: Either[Throwable, A]) = new RichEither(e) |
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
| abstract class ProxyT[T <: ProxyT[T]](implicit cm: ClassManifest[T]) { | |
| val underlying: Any | |
| override def hashCode: Int = underlying.hashCode | |
| override def equals(other: Any): Boolean = other match { | |
| case that: T if(cm.erasure.isInstance(that)) => underlying.equals(that.underlying) | |
| case _ => false | |
| } | |
| } |
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
| scala> val a: Either[Exception, Either[Exception, Int]] = Right(Right(10)) | |
| a: Either[Exception,Either[Exception,Int]] = Right(Right(10)) | |
| scala> a.joinRight | |
| res0: Either[Exception,Int] = Right(10) | |
| scala> val b: Either[Exception, Either[Exception, Int]] = Right(Left(new Exception("a"))) | |
| b: Either[Exception,Either[Exception,Int]] = Right(Left(java.lang.Exception: a)) | |
| scala> b.joinRight |
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
| 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 test(): Unit = { | |
| for(i <- 1 to 10) { | |
| println(i); | |
| if(i == 5) return; | |
| } | |
| println("test"); //実行されたら気持ち悪い | |
| } |
OlderNewer