Closure Syntax
Closures are created with vertical bars: |..| ..
.
Speaker Notes
This slide should take about 3 minutes.
-
The arguments go between the
|..|
. The body can be surrounded by{ .. }
, but if it is a single expression these can be omitted. -
Argument types are optional, and are inferred if not given. The return type is also optional, but can only be written if using
{ .. }
around the body. -
The examples are both lambdas – they do not capture anything from their environment. We will see captures next.