for式はforeach
Last active
August 29, 2015 14:17
-
-
Save fkmt-disk/85048538f14f6503a729 to your computer and use it in GitHub Desktop.
for式はforeach
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
lazy val root = (project in file(".")).settings( | |
scalaVersion := "2.11.5", | |
scalacOptions += "-Xprint:typer" | |
) |
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
package sample1 | |
object Main extends App { | |
val seq = Seq(1, 2, 3) | |
for (i <- seq) println(i) | |
} |
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
[[syntax trees at end of typer]] // sample1.scala | |
package sample1 { | |
object Main extends AnyRef with App { | |
def <init>(): sample1.Main.type = { | |
Main.super.<init>(); | |
() | |
}; | |
private[this] val seq: Seq[Int] = collection.this.Seq.apply[Int](1, 2, 3); | |
<stable> <accessor> def seq: Seq[Int] = Main.this.seq; | |
Main.this.seq.foreach[Unit](((i: Int) => scala.this.Predef.println(i))) | |
} | |
} |
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
package sample2 | |
object Main extends App { | |
object Eachable { | |
import scala.util.Random | |
private val random = new Random | |
// ランダムな数値を引数に3回呼び出す。 | |
def foreach(f: (Int) => Unit) = { | |
f(random.nextInt) | |
f(random.nextInt) | |
f(random.nextInt) | |
} | |
} | |
for (i <- Eachable) println(i) | |
} |
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
[[syntax trees at end of typer]] // sample2.scala | |
package sample2 { | |
object Main extends AnyRef with App { | |
def <init>(): sample2.Main.type = { | |
Main.super.<init>(); | |
() | |
}; | |
object Eachable extends scala.AnyRef { | |
def <init>(): sample2.Main.Eachable.type = { | |
Eachable.super.<init>(); | |
() | |
}; | |
import scala.util.Random; | |
private[this] val random: scala.util.Random = new scala.util.Random(); | |
<stable> <accessor> private def random: scala.util.Random = Eachable.this.random; | |
def foreach(f: Int => Unit): Unit = { | |
f.apply(Eachable.this.random.nextInt()); | |
f.apply(Eachable.this.random.nextInt()); | |
f.apply(Eachable.this.random.nextInt()) | |
} | |
}; | |
Main.this.Eachable.foreach(((i: Int) => scala.this.Predef.println(i))) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment