Created
July 4, 2017 12:47
-
-
Save piton4k/b41de296d76c8c9637df1c7145cffe53 to your computer and use it in GitHub Desktop.
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
def lazyFun(aThing: => Unit) = { | |
println("doing a thing") | |
aThing | |
println("done") | |
} | |
// correct | |
lazyFun(println("a thing")) | |
// incorrect - compiles thanks to value discard, but doesn't print | |
lazyFun(() => println("another thing")) | |
trait MyUnit | |
object MyUnit extends MyUnit | |
def lazyFun2(aThing: => MyUnit) = { | |
println("doing a thing") | |
aThing | |
println("done") | |
} | |
// correct | |
lazyFun2({ println("a thing"); MyUnit }) | |
// these won't compile | |
// lazyFun2(() => { println("another thing"); MyUnit }) | |
// lazyFun2({ () => println("another thing"); MyUnit }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment