
Suspending functions belong to a special kind of function type that have a suspend modifier in their notation, such as suspend () -> Unit or suspend A.(B) -> C. Function literals with receiver are often used along with these types. The Unit return type cannot be omitted.įunction types can optionally have an additional receiver type, which is specified before the dot in the notation: the type A.(B) -> C represents functions that can be called on a receiver object A with a parameter B and return a value C. The list of parameter types may be empty, as in () -> A. These types have a special notation that corresponds to the signatures of the functions - their parameters and return values:Īll function types have a parenthesized list of parameter types and a return type: (A, B) -> C denotes a type that represents functions that take two arguments of types A and B and return a value of type C. Kotlin uses function types, such as (Int) -> String, for declarations that deal with functions: val onClick: () -> Unit =. Println("joinedToString = $joinedToString") Function references can also be used for higher-order function calls: Val joinedToString = items.fold("Elements:", ) Parameter types in a lambda are optional if they can be inferred: The last expression in a lambda is considered the return value: When a lambda has parameters, they go first, followed by '->'



Lambdas are code blocks enclosed in curly braces.
