Skip to content

Commit d3ec845

Browse files
Merge pull request #71 from josephpconley/patch-1
Adding closure documentation
2 parents d2d632a + db12075 commit d3ec845

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/main/scala/stdlib/HigherOrderFunctions.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,13 @@ object HigherOrderFunctions extends FlatSpec with Matchers with org.scalaexercis
4646
result should be(res0)
4747
}
4848

49-
/** {{{
49+
/** Here the only variable used in the function body, `i * 10`, is `i`, which is defined as a parameter to the function.
50+
*
51+
*{{{
5052
* val multiplier = (i:Int) => i * 10
5153
* }}}
5254
*
53-
* Here the only variable used in the function body, `i * 10`, is `i`, which is defined as a parameter to the function.
55+
* A closure is a function which maintains a reference to one or more variables outside of the function scope (it "closes over" the variables). Scala will detect that you are using variables outside of scope and create an object instance to hold the shared variables.
5456
*/
5557
def meetClosureHigherOrderFunctions(res0: Int, res1: Int) {
5658
var incrementer = 1

0 commit comments

Comments
 (0)