Skip to content

Commit 336411e

Browse files
jjELTSethTisue
authored andcommitted
Added an example on how to use anonymous functions in the "Anonymous … (#628)
Added an example on how to use anonymous functions in the "Anonymous Function Syntax" page (tutorials/tour/anonymous-function-syntax.md). Omitted the, apparently for Scala unconventional, usage of 'var's in the code. Example is now slimmer, i.e. there is only one line in the main method where the anonymous function is called once and the return value is immediately printed.
1 parent 441648d commit 336411e

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

Diff for: tutorials/tour/anonymous-function-syntax.md

+22
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,25 @@ Function1[Int, Int]
5151
Function2[Int, Int, String]
5252
Function0[String]
5353
```
54+
55+
The following example shows how to use anonymous function of the beginning of this page
56+
57+
```tut
58+
object AnonymousFunction {
59+
60+
/**
61+
* Method to increment an integer by one.
62+
*/
63+
val plusOne = (x: Int) => x + 1
64+
65+
/**
66+
* Main method
67+
* @param args application arguments
68+
*/
69+
def main(args: Array[String]) {
70+
71+
println(plusOne(0)) // Prints: 1
72+
73+
}
74+
}
75+
```

0 commit comments

Comments
 (0)