Coding Friction


Infix Function

In Kotlin, infix functions allow you to call functions with a single argument without using the traditional dot and parentheses syntax. This can make your code more readable and expressive, especially when you’re working with DSLs (Domain Specific Languages) or building fluent APIs. To define an infix function in Kotlin, you need to: Here’s an …

Infix Function Read More »

Higher order function

In Kotlin, a higher-order function is a function that takes one or more functions as arguments, or returns a function as its result. It enables you to treat functions as first-class citizens, meaning you can use them just like any other values, such as integers or strings. Passing lambda expression as a parameter to Higher-Order …

Higher order function Read More »

Kotlin Lambda Function

Lambda is a function which has no name. It is a concise way to define a block of code that can be passed around as an argument to higher-order functions or stored in a variable for later use. Lambda functions are useful in various contexts, such as higher-order functions, collections operations (like map, filter, and …

Kotlin Lambda Function Read More »

Kotlin Default and Named Argument

Default Arguments: Kotlin provides a facility to  assign default values to function parameters. When calling a function, if not provide a value for a parameter with a default value, the default value will be used. It allows you to call the function with fewer arguments if desired. Here’s an example of a function with default …

Kotlin Default and Named Argument Read More »

Kotlin Recursion function

A recursive function is a function that calls itself in its own definition.  Let’s look at an example of a simple recursive function to calculate the factorial of a number: When you call factorial(5), the recursive calls break down as follows: The function repeatedly calls itself with smaller values until it reaches the base case, …

Kotlin Recursion function Read More »

Kotlin function

Functions are blocks of code that perform a specific task and can be called multiple times within a program. By using functions, we can avoid repeating the same code, which makes our program cleaner and more organized. functions are declared using fun keyword in kotlin Let’s create a simple example that calculates the area of …

Kotlin function Read More »

Kotlin Array

Array is a collection of similar data types such as an Int, String etc. It is used to organize data so sorted and searched can be easily done. Arrays are mutable and fixed size, they are stored in contiguous memory locations. Create an Array : In Kotlin there are two ways to create an array 1. …

Kotlin Array Read More »

Kotlin Return and jump

These are the jump expression are used to control the flow of program execution. return : By default returns from the nearest enclosing function or anonymous function continue : Proceeds to the next step of the nearest enclosing loop break : It is used to  terminates the nearest enclosing loop. it is used to bring …

Kotlin Return and jump Read More »

Kotlin do-while loop

do-while loop first executes the code of do block then it checks the┬ácondition. do-while loop executes at least once even the condition of while is false. Syntax Example Let’s see an example where a block of code executes only once and the condition in while is false.

Kotlin while Loop

It is used to iterate a part of code several times. It executes until the condition is true. Syntax let’s take an example: Iterate through Array using while loop