add old scala exercises
parent
cff314486c
commit
c3408fb74a
@ -0,0 +1,18 @@
|
|||||||
|
object Pipelining {
|
||||||
|
implicit def toPipe[T](x : T) = new { def |> [U](f : T => U) = f(x) }
|
||||||
|
}
|
||||||
|
|
||||||
|
object PipelineTest extends App {
|
||||||
|
|
||||||
|
def minusTen(x: Int) = x-10
|
||||||
|
|
||||||
|
def timesTwo(x: Int) = x*2
|
||||||
|
|
||||||
|
assert(minusTen(timesTwo(3)) == -4)
|
||||||
|
|
||||||
|
val f = timesTwo _ andThen minusTen _
|
||||||
|
assert(f(3) == -4)
|
||||||
|
|
||||||
|
val g = timesTwo compose minusTen
|
||||||
|
assert(g(3) == -4)
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
import scalafx.Includes._
|
||||||
|
import scalafx.application.JFXApp
|
||||||
|
import scalafx.scene.Scene
|
||||||
|
import scalafx.scene.paint.Color
|
||||||
|
import scalafx.scene.shape.Rectangle
|
||||||
|
|
||||||
|
object ScalaFXHello extends JFXApp {
|
||||||
|
stage = new JFXApp.PrimaryStage {
|
||||||
|
title.value = "Hello Stage"
|
||||||
|
width = 600
|
||||||
|
height = 450
|
||||||
|
scene = new Scene {
|
||||||
|
fill = Color.LightGreen
|
||||||
|
content = new Rectangle {
|
||||||
|
x = 25
|
||||||
|
y = 40
|
||||||
|
width = 100
|
||||||
|
height = 100
|
||||||
|
fill <== when (hover) choose Color.Green otherwise Color.Red
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
// http://daily-scala.blogspot.de/2009/09/lazy-val.html
|
||||||
|
|
||||||
|
object Lazyvals extends App {
|
||||||
|
val normalVal = {
|
||||||
|
println("---->>> Initializing normal val <<<----");
|
||||||
|
"This is the normal val"
|
||||||
|
}
|
||||||
|
lazy val lazyVal = {
|
||||||
|
println("---->>> Initializing lazy val <<<----");
|
||||||
|
"This is the lazy val"
|
||||||
|
}
|
||||||
|
println("\n\nno references have been made yet\n\n")
|
||||||
|
println("Accessing normal val : ")
|
||||||
|
println(normalVal)
|
||||||
|
println("\n\nAccessing lazy val : ")
|
||||||
|
println(lazyVal)
|
||||||
|
println("\n\nAccessing lazy val a second time, there should be no initialization now: ")
|
||||||
|
println(lazyVal)
|
||||||
|
}
|
Loading…
Reference in New Issue