July 2017
Intermediate to advanced
796 pages
18h 55m
English
As mentioned, higher-order functions also support returning a function as a result. Let's demonstrate this by an example:
def transferMoney(money: Double) = { if (money > 1000) (money: Double) => "Dear customer we are going to add the following amount as Fee: "+money * 0.05 else (money: Double) => "Dear customer we are going to add the following amount as Fee: "+money * 0.1} val returnedFunction = TransferMoney(1500)returnedFunction(1500)
The preceding code segment will produce the following output:
Dear customer, we are going to add the following amount as Fee: 75.0
Let's run the previous example as shown in the following screenshot; it shows how to use the function as a return value:
Read now
Unlock full access