Named arguments

Scala allows you to specify parameter assignment by name rather than just ordinal position. For example, we can have this code:

def divide(dividend:Int, divisor:Int): Float = 
{ dividend.toFloat / divisor.toFloat }
divide(40, 5)
divide(divisor = 40, dividend = 5)

If we run this in a notebook, we can see the results:

Named arguments

The first call is to divide assigned parameters by position. The second call set them accordingly.

Get Learning Jupyter now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.