Kotlin Tutorial #16: Sequences — Lazy Collections for Performance

In the previous tutorial, you learned about delegation. Now let’s learn about sequences. Sequences are lazy collections that process elements one at a time instead of all at once. This can make a big difference in performance when working with large data sets. In this tutorial, you will learn: Sequences vs Lists (lazy vs eager) Creating sequences generateSequence Sequence builders with yield and yieldAll Infinite sequences When to use sequences Performance comparison Practical examples Sequences vs Lists Lists are eager — they process all elements at each step and create intermediate collections. Sequences are lazy — they process one element through all steps before moving to the next. ...

March 22, 2026 · 9 min

Kotlin Tutorial #15: Delegation — by lazy, Delegates, and Custom Delegation

In the previous tutorial, you learned about error handling. Now let’s learn about delegation. Delegation is a design pattern where an object hands off work to another object. Kotlin has built-in support for delegation using the by keyword. In this tutorial, you will learn: by lazy — lazy initialization Delegates.observable — react to changes Delegates.vetoable — reject invalid changes Map delegation — properties from a map Custom delegates — build your own Class delegation — delegate interface implementation by lazy by lazy creates a property that is computed only once, the first time you access it. After that, the cached value is returned. This is useful for expensive initialization. ...

March 22, 2026 · 8 min

Kotlin Tutorial #14: Error Handling — try/catch, Result, and Patterns

In the previous tutorial, you learned about interfaces and generics. Now let’s learn about error handling. Every program needs to handle errors. Kotlin gives you several tools for this, from traditional try/catch to the modern Result type. In this tutorial, you will learn: try/catch/finally try as an expression Custom exceptions The Result type (runCatching, getOrElse, map, fold) Sealed classes for errors Error handling patterns and best practices try/catch/finally The try/catch block catches exceptions. finally always runs, even after an exception. ...

March 22, 2026 · 8 min

Kotlin Tutorial #13: Interfaces, Generics, and Type Constraints

In the previous tutorial, you learned about sealed classes, enum classes, and value classes. Now let’s learn about interfaces, generics, and type constraints. These features let you write flexible, reusable code while keeping type safety. In this tutorial, you will learn: Interfaces and multiple inheritance Generics with <T> Type constraints with where Variance — in and out Star projection * Reified type parameters Interfaces An interface defines a contract. Classes that implement the interface must provide the required functions and properties. ...

March 22, 2026 · 8 min

Kotlin Tutorial #12: Sealed Classes, Enum Classes, and Value Classes

In the previous tutorial, you learned about scope functions. Now let’s learn about three important types in Kotlin: enum classes, sealed classes, and value classes. Each one solves a different problem, and knowing when to use which will make your code better. In this tutorial, you will learn: Enum classes — fixed set of constants Sealed classes — restricted hierarchies with different data Sealed interfaces — multiple inheritance with sealed types Value classes — type safety without runtime overhead When to use which Enum Classes An enum class defines a fixed set of constants. Every value is known at compile time. ...

March 22, 2026 · 9 min

Kotlin Tutorial #10: Extension Functions and Properties

In the previous tutorial, you learned about lambdas and higher-order functions. Now let’s learn about extension functions and properties. Extensions let you add new functions and properties to existing classes without modifying them. This is one of Kotlin’s best features. You can add a toSlug() function to String or a secondOrNull() function to List — without changing the original class. In this tutorial, you will learn: Extension functions Practical extensions like String.toSlug() and List.secondOrNull() Extension properties Extensions on nullable types Companion object extensions Generic extensions Extension Functions An extension function adds a new function to an existing class. The class you extend is called the “receiver.” ...

March 22, 2026 · 8 min

Kotlin Tutorial #9: Lambdas and Higher-Order Functions

In the previous tutorial, you learned about collections. Now let’s learn about lambdas and higher-order functions. These are some of the most powerful features in Kotlin. A lambda is a function without a name. You already used lambdas with filter, map, and other collection functions. In this tutorial, you will learn how they work in depth. In this tutorial, you will learn: Lambda syntax and the it keyword Trailing lambdas Function types like (Int) -> String Higher-order functions (functions that take or return functions) Function references Closures Inline functions Lambda Syntax A lambda is written between curly braces { }. The arrow -> separates the parameters from the body. ...

March 22, 2026 · 9 min

Kotlin Tutorial #11: Scope Functions — let, run, with, apply, also

In the previous tutorial, you learned about extension functions. Now let’s learn about scope functions. Kotlin has five scope functions: let, run, with, apply, and also. They execute a block of code on an object and differ in how they refer to the object and what they return. These functions are used everywhere in Kotlin code. Understanding them will make your code cleaner and more readable. ...

March 19, 2026 · 9 min