0Pricing
Kotlin Multiplatform Academy · Lesson

map, filter & fold in Shared Code

Functional collection operators you can rely on cross-platform.

map, filter & fold in Shared Code is a free Kotlin Multiplatform Academy lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Kotlin Multiplatform Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Transform Without Loops

Kotlin gives collections functional operators that transform data cleanly. They all run identically in shared multiplatform code.

map Reshapes Each Item

map applies a function to every element and returns a new list of the results, leaving the original untouched.

val nums = listOf(1, 2, 3)
val doubled = nums.map { it * 2 }

map Changes the Type

The output of map can be a different type than the input, so a list of ints can become a list of strings.

val labels = nums.map { "item " + it }

filter Keeps What You Want

filter returns only the elements that match a condition, dropping the rest into a fresh list.

val evens = nums.filter { it % 2 == 0 }

Chain map and filter

You can chain operators so each step feeds the next, reading cleanly from left to right.

val result = nums.filter { it > 1 }.map { it * 10 }

fold Combines Into One

fold reduces a whole list to a single value, starting from a seed and combining each item in turn.

val sum = nums.fold(0) { acc, n -> acc + n }

fold Builds Any Result

The accumulator in fold can be any type, so you can build a string, a total or even a new collection.

val joined = nums.fold("") { acc, n -> acc + n }

Lambdas and it

These operators take a lambda. With one parameter, Kotlin names it it, keeping the code short and readable.

val squares = nums.map { it * it }

Originals Stay Safe

map, filter and fold never mutate the source list. They return new results, which keeps shared logic predictable.

Perfect for Shared Logic

Because these operators are pure and platform-neutral, they are ideal for the data crunching that lives in commonMain. 🙂

More in the Family

map, filter and fold have siblings like sumOf, count and groupBy. All are multiplatform and worth exploring.

Quick Check

Which operator collapses a list to one value?

Recap

map reshapes, filter selects and fold combines. These pure, multiplatform operators make shared data logic clear and safe.

Frequently asked questions

Is the “map, filter & fold in Shared Code” lesson free?

Yes — the full text of “map, filter & fold in Shared Code” is free to read here on the web, and the Kotlin Multiplatform Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Kotlin Multiplatform Academy course, upgrade to CoddyKit PRO.

What will I learn in “map, filter & fold in Shared Code”?

Functional collection operators you can rely on cross-platform. You practise Kotlin Multiplatform Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Kotlin Multiplatform Academy?

No prior experience is required. Kotlin Multiplatform Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “map, filter & fold in Shared Code” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Kotlin Multiplatform Academy lesson?

Yes. Every Kotlin Multiplatform Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Strings, Numbers & Collections Everywhere
  2. map, filter & fold in Shared Code
  3. Dates with kotlinx-datetime
  4. What Is NOT in Common stdlib
← Back to Kotlin Multiplatform Academy