

This looks confusing, right? It would be clearer if I rewrite it like this (this is equivalent): (String) -> (( Int) -> Boolean) Now, can you guess this one? (String) -> ( Int) -> Boolean For example:Ī function without arguments that doesn't return anything: () -> UnitĪ function with two string arguments that returns a boolean: (String, String) -> Boolean A function type that doesn't return anything must use the return type Unit.

You put the type(s) of the parameter(s) in the left-side parenthesis and the return type on the right side. as a parameter to another function) or as the type of a variable holding a function reference. Ī function type is a special notation Kotlin uses to represent a function - basically its signature - that can be used to declare a function (e.g. 🔖 I created this Table of Contents using BitDownToc. To better understand what it means, and why it is so cool, let's go through the theory: what are function types, why they matter, and how they relate to lambdas and higher order functions.ĭid I lose you? Then read on! Everything will become clear, I promise! 😊 This is one of the idioms of functional programming, a programming style that I love. Kotlin treats functions as first-class citizens.įirst-class means functions can be stored in variables and data structures and can be passed as arguments to and returned from other functions ( higher-order functions).
