Functions in Drizzle are defined using the def
keyword.
def multiply_message(msg: str, times: int = 5) {to_print = msg * timesprintln(to_print)}# In this example we show that Drizzle supports default paramsmultiply_message('a') # Prints 'aaaaa'multiply_message('a', 3) # Prints 'aaa'
Drizzle also supports simple one line functions;
def multiply_message(msg: str, times: int = 5) = println(msg * times)
Return types of the function are shown through the use of the ->
operator
def test() -> int = return 3
If no return type is explicitly described, the null
type is assumed to be the return type. The null
type is returned from a function in 3 cases: 1. When there's no return
statement in the function. 2. When there's an empty return
statement in the function. 3. When null
is explicitly returned from the function.