Learning Scala Programming
上QQ阅读APP看书,第一时间看更新

Function literals

Function literals are a syntactical way of representing a function. The basic structure of a function is something that can take some parameters and return a response. If we've to represent a function that takes an Int value and respond in String, it will be like this:

Int => String

The left-hand side represents the input parameters, and the right-hand side gives parameters that are response type. The type of preceding function literal is Function1[Int, String], and parameters Int and String are representing input and output parameters respectively. We'll discuss these more when we talk about functions in subsequent chapters.

We have discussed how literals are represented in Scala, and now that we know this, we've got a heads up to go ahead with data types.