mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-25 16:23:37 +03:00
Merge pull request #547 from rostdotio/master
[scala] Added explanation for colon character
This commit is contained in:
commit
dd71873b2d
@ -104,10 +104,13 @@ val sq = (x:Int) => x * x
|
|||||||
|
|
||||||
sq(10) // Gives you this: res33: Int = 100.
|
sq(10) // Gives you this: res33: Int = 100.
|
||||||
|
|
||||||
|
// The colon explicitly defines the type of a value, in this case a function
|
||||||
|
// taking an Int and returning an Int.
|
||||||
|
val add10: Int => Int = _ + 10
|
||||||
|
|
||||||
// Scala allows methods and functions to return, or take as parameters, other
|
// Scala allows methods and functions to return, or take as parameters, other
|
||||||
// functions or methods.
|
// functions or methods.
|
||||||
|
|
||||||
val add10: Int => Int = _ + 10 // A function taking an Int and returning an Int
|
|
||||||
List(1, 2, 3) map add10 // List(11, 12, 13) - add10 is applied to each element
|
List(1, 2, 3) map add10 // List(11, 12, 13) - add10 is applied to each element
|
||||||
|
|
||||||
// Anonymous functions can be used instead of named functions:
|
// Anonymous functions can be used instead of named functions:
|
||||||
|
Loading…
Reference in New Issue
Block a user