FlashKeepers

Kotlin · College · College and University

Kotlin II: Functions and Collections

Kotlin functions, default arguments, lambdas, higher-order functions, collection operations, sequences and scope functions.

About this set

40 basic cards for College Kotlin. Set 2 of 4 in Kotlin. It opens with "How do you declare a function with parameters and return type in Kotlin?" and "How do you define a default parameter value in Kotlin?". Study it alongside the other College sets below.

40 cards · basic cards · AI-written, checked twice. Edit anything.

Study this set free Look inside first Get FlashKeepers for iPhone

Opens in your browser, no account. Get the iPhone and iPad app · Android app

How do you declare a function with parameters and return type in Kotlin?
Show answerfun functionName(param1: Type, param2: Type): ReturnType { ... }
How do you define a default parameter value in Kotlin?
Show answerfun greet(name: String = "World") { ... }
What is a named argument in Kotlin?
Show answerPassing arguments by name, e.g., greet(name = "Alice")
How do you write a single-expression function?
Show answerfun add(a: Int, b: Int) = a + b
What does Unit represent as a return type?
Show answerThe absence of a meaningful return value, equivalent to void in Java
Can you omit the return type in Kotlin if it is obvious?
Show answerYes, Kotlin can infer return types in most contexts
How do you declare a function type in Kotlin?
Show answer(ParameterType) -> ReturnType, for example (Int, Int) -> String
What is the basic syntax for a lambda expression?
Show answer{ param -> expression } or { (param1, param2) -> expression }
How do you write a lambda with multiple parameters?
Show answer{ x, y -> x + y } or { (x: Int, y: Int) -> x + y }
How do you write a lambda with no parameters?
Show answer{ } or { -> code }
Define a higher-order function
Show answerA function that takes another function as a parameter or returns a function
How do you pass a lambda to a higher-order function?
Show answerPass it as an argument, optionally using trailing lambda syntax outside parentheses
What is the main difference between lambda and anonymous function?
Show answerAnonymous functions have explicit return types; lambdas use implicit return of the last expression
What does the let scope function do?
Show answerExecutes a code block with the object as parameter (it) and returns the block result
What does the run scope function do?
Show answerExecutes a code block with the object as this and returns the block result

25 more cards in the app

Study this set free