Last active
December 28, 2015 14:58
-
-
Save JohnMurray/7518029 to your computer and use it in GitHub Desktop.
Blog post
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
val s1 = {"hello"} // s1: String = hello | |
val s = "hello" // s: String = hello |
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
val f1 = (x : Int => x * x) // invalid - compiler error (can't resolve x) | |
val f2 = (x : Int) => x * x // valid | |
val f3 = {x : Int => x * x} // valid |
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
def map[B, That](f: A => B)(implicit bf: CanBuildFrom[Repr, B, That]): That = { | |
def builder = { // extracted to keep method size under 35 bytes, so that it can be JIT-inlined | |
val b = bf(repr) | |
b.sizeHint(this) | |
b | |
} | |
val b = builder | |
for (x <- this) b += f(x) | |
b.result | |
} |
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
val list = List(1, 2, 3, 4) | |
list.map(x => x * x) |
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
val list = List(1, 2, 3, 4) | |
list.map { x => x * x } |
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
val list = List(1, 2, 3, 4) | |
list.map(x => x * x) | |
list.map({x => x * x}) |
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
val list = List(1, 2, 3, 4) | |
// not valid (compile-error) | |
list.map(x => | |
val y = x * x | |
val z = y * x | |
Math.sin(z / x) | |
) | |
// valid | |
list.map{x => | |
val y = x * x | |
val z = y * x | |
Math.sin(z / x) | |
} |
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
def echo(x: String) = println(x) | |
echo{"hello"} // valid | |
echo("hello") // valid | |
def echoName(name: String, x: String) = println("$name: $x") | |
echoName{"John", "hello"} // invalid | |
echoName("John", "hello") // valid | |
echoName({"John"}, {"hello"}) // valid |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment