Skip to content

Commit

Permalink
Added explanation for colon character
Browse files Browse the repository at this point in the history
Use of the colon character for value assignment is now explained by example of function add10.
  • Loading branch information
rostdotio committed Feb 28, 2014
1 parent 31b5427 commit bd6d3be
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion scala.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,13 @@ val sq = (x:Int) => x * x

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
// 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

// Anonymous functions can be used instead of named functions:
Expand Down

0 comments on commit bd6d3be

Please sign in to comment.