Created
November 26, 2014 09:14
-
-
Save piyo7/93c253e6e017e2c5c1dd to your computer and use it in GitHub Desktop.
一時オブジェクトの生成コスト回避による高速化 ref: http://qiita.com/piyo7/items/c8e576c6b010256c66f9
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> Seq(1, 2, 3).view.map(_ + 1).map(_ * 2) | |
res0: scala.collection.SeqView[Int,Seq[_]] = SeqViewMM(...) | |
scala> res0.force | |
res1: Seq[Int] = List(4, 6, 8) |
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
override def map[B, That](f: A => B)(implicit bf: CanBuildFrom[This, B, That]): That = { | |
newMapped(f).asInstanceOf[That] | |
} |
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
protected def newMapped[B](f: A => B): Transformed[B] = new { val mapping = f } with AbstractTransformed[B] with Mapped[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
trait Mapped[B] extends Transformed[B] { | |
protected[this] val mapping: A => B | |
def foreach[U](f: B => U) { | |
for (x <- self) | |
f(mapping(x)) | |
} | |
final override protected[this] def viewIdentifier = "M" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment