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
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
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 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
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
/* | |
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
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") |
NewerOlder