flâneur — a map of the web's best reading

Higher-order functions and lambdas | Kotlin Documentation

kotlinlang.org · 2,296 words · saved by 1 readers

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. To facilitate this, Kotlin, as a statically typed programming language, uses a family of function types to represent functions, and provides a set of specialized language constructs, such as lambda expressions. A higher-order function is a function that takes functions as parameters, or returns a function. A good example of a higher-order function is the functional programming idiom fold for collections. It takes an initial accumulator value and a combining function and builds its return value by consecutively combining the current accumulator value with each collection element, replacing the accumulator value each time: In the code above, the combine parameter has the function type (R, T) -> R, so it accepts a funct

Higher-order functions and lambdas 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. To facilitate this, Kotlin, as a statically typed programming language, uses a family of function types to represent functions, and provides a set of specialized language constructs, such as lambda expressions . Higher-order functions A higher-order function is a function that takes funct

Explore this link on the map →

related reading