Problem Statement
Explain Unit, Nothing, and single-expression functions in Kotlin.
Explanation
Unit is Kotlin's type for functions that don't return a meaningful value equivalent to void in Java, but Unit is an actual type with a singleton value allowing it to be used in generic contexts. You can omit Unit return type declaration as it's the default, and functions returning Unit can use return without a value or simply let the function end.
Nothing is a special type representing a value that never exists, used for functions that never return normally like functions that always throw exceptions or enter infinite loops. Nothing is a subtype of all types making it useful in type-safe error handling and control flow analysis where the compiler knows execution doesn't continue.
Single-expression functions can use equals syntax instead of curly braces like fun double open paren x colon Int close paren equals x times 2, automatically inferring the return type from the expression. This syntax is concise for simple functions and clearly indicates the function is pure with no side effects, commonly used for property getters, simple transformations, and lambda-like utility functions.
