Skip to content

Latest commit

 

History

History
44 lines (32 loc) · 964 Bytes

06_lazyness.md

File metadata and controls

44 lines (32 loc) · 964 Bytes

Scala language feature: Lazyness

Overview of definition keywords

Lazy val

lazy val a: Int = {
    println("set!")
    3
}

By-name parameters

def test(value: => Int): Int = {
    if (value > 0) 0 else value * 2
}
test {
    println("test")
    scala.util.Random.nextInt
}

https://stackoverflow.com/questions/4543228/whats-the-difference-between-and-unit

Lazyness is like functions as values

Streams as infinite lists

Simple example of DSL

References