An anonymous function can also take on a different look by taking out the brackets
Function taking another function as parameter.
Function taking another function as parameter. Helps in composing functions.
Hint: a map method applies the function to each element of a list
We can take that closure and throw into a method and it will still hold the environment
isInstanceOf
is the same as instanceof
in java, but in this case the parameter types can be *blanked out* using existential types with a single underline, since parameter type are unknown at runtime.
val multiplier = (i:Int) => i * 10
Here the only variable used in the function body, i * 10
, is i
, which is defined as a parameter to the function.
Meet lambda.
Meet lambda. Scala provides a relatively lightweight syntax for defining anonymous functions. Anonymous functions in source code are called function literals and at run time, function literals are instantiated into objects called function values.
Scala supports first-class functions, which means you can express functions in function literal syntax, i.e., (x: Int) => x + 1
, and that functions can be represented by objects, which are called function values.
Function returning another function using an anonymous function:
Function returning another function:
This method has been deprecated in favor of macro assertion and will be removed in a future version of ScalaTest. If you need this, please copy the source code into your own trait instead.
This method has been deprecated in favor of macro assertion and will be removed in a future version of ScalaTest. If you need this, please copy the source code into your own trait instead.
This method has been deprecated in favor of macro assumption and will be removed in a future version of ScalaTest. If you need this, please copy the source code into your own trait instead.
This method has been deprecated in favor of macro assumption and will be removed in a future version of ScalaTest. If you need this, please copy the source code into your own trait instead.
Please use 'an [Exception] should be thrownBy { ... }' syntax instead
This expect method has been deprecated. Please replace all invocations of expect with an identical invocation of assertResult instead.
This expect method has been deprecated. Please replace all invocations of expect with an identical invocation of assertResult instead.
This expectResult method has been deprecated. Please replace all invocations of expectResult with an identical invocation of assertResult instead.
This expectResult method has been deprecated. Please replace all invocations of expectResult with an identical invocation of assertResult instead.