Select all correct ways to use function literals.
Explanation
The general way is:
someList.filter((x: Int) => x > 0)
However, Scala provides a number of ways to write function literals more briefly. One way is to leave off the parameter types.
someList.filter((x) => x > 0)
This is called target typing, because the targeted usage of an expression (an argument to someList.filter()) is allowed to influence the typing of that expression (to determine the type of the x parameter).

The next way to remove useless characters is to leave out parentheses around a parameter whose type is inferred.
someList.filter(x => x > 0)
To make a function literal even more concise, you can use underscores as placeholders for parameters.
someList.filter( _ > 0)
Read more: Short forms of function literals

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Keep exploring
Scala quizzes
Cosmo
Sign Up Now
or Subscribe for future quizzes