Kotlin Concepts Flashcards
Kotlin functions are first-class, which means?
they can be stored in variables and data structures, and can be passed as arguments to and returned from other higher-order functions.
You can perform any operations on functions that are possible for other non-function values.
Kotlin, as a statically typed programming language means?
variable types are explicitly declared and thus are determined at compile time
What is a Higher-order function?
a function that takes functions as parameters, or returns a function.
All function types have a parenthesized list of parameter types and a return type: (A, B) -> C
What does this denote?
denotes a type that represents functions that take two arguments of types A and B and return a value of type C. The list of parameter types may be empty, as in () -> A. The Unit return type cannot be omitted.
Function types can optionally have an additional receiver type, which is specified before the dot in the notation: the type A.(B) -> C
What does this represent?
represents functions that can be called on a receiver object A with a parameter B and return a value C.
Function literals with receiver are often used along with these
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.
To specify that a function type is nullable use… ?
parentheses as follows: ((Int, Int) -> Int)?
You can also give a function type an alternative name by…?
using a type alias:
typealias ClickHandler = (Button, ClickEvent) -> Unit
function literals are?
functions that are not declared but are passed immediately as an expression.
Name two types of function literals?
Lambda expressions & anonymous functions