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
implicit def seq2Distinct[T, C[T] <: Seq[T]](tees: C[T]) = new { | |
import collection.generic.CanBuildFrom | |
import collection.mutable.{HashSet => MutableHashSet} | |
def distinctBy[S](hash: T => S)(implicit cbf: CanBuildFrom[C[T],T,C[T]]): C[T] = { | |
val builder = cbf() | |
val seen = MutableHashSet[S]() | |
for (t <- tees) { | |
if (!seen(hash(t))) { |
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
implicit def iterable2Cross[T, C[T] <: Iterable[T]](tees: C[T]) = new { | |
import collection.generic.CanBuildFrom | |
def cross[S](esses: Iterable[S])(implicit cbf: CanBuildFrom[C[(T,S)],(T,S),C[(T,S)]]): C[(T,S)] = { | |
val builder = cbf() | |
val rst = for (t <- tees; s <- esses) yield (t, s) | |
rst foreach { builder += } | |
builder.result |
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
> test | |
... | |
[info] Test Starting - BenchmarksTest: SourceBenchmark | |
Mean: 392.100000 | |
StdDev: 5.022947 | |
[info] Test Succeeded - BenchmarksTest: SourceBenchmark | |
[info] Test Starting - BenchmarksTest: InputStreamBenchmark | |
Mean: 69.610000 |
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
scala> def test = { println("Evaluating"); "test" } | |
test: java.lang.String | |
scala> case class TestClass(s: String) { override def toString = "overrided so the REPL doesn't coerse evaluation of s" } | |
defined class TestClass | |
scala> val t = TestClass(test) | |
Evaluating | |
t: TestClass = overrided so the REPL doesn't coerse evaluation of s |
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
scala> val l = List((1,2), (2,3)) | |
l: List[(Int, Int)] = List((1,2), (2,3)) | |
scala> l map { case (i, j) => i+j } | |
res5: List[Int] = List(3, 5) | |
scala> import Function.tupled | |
import Function.tupled | |
scala> l map tupled { (i, j) => i + j } |
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
trait InMainThread { | |
private val handler = new Handler | |
def mainThread(block: => Unit) { | |
handler.post(new Runnable { | |
def run { block } | |
}) | |
} | |
} |
NewerOlder