CodeGym
AI Academy
Promotion
CodeGym University
Learning
Courses
Tasks
Surveys & Quizzes
Games
Help
Schedule
Community
Users
Forum
Chat
Articles
Success stories
Activity
Reviews
Subscriptions
Light theme

Lessons

  • Reviews
  • About us
Start
Start learning
Start learning now
  • My Progress
  • Courses
  • University
  • Quest Map
  • Lessons
  • Lambda Expressions in Kotlin: Syntax, it, Return Value

    Kotlin SELF
    Level 21, Lesson 0
    We break down Kotlin lambda expressions as “values”: how to store a lambda in val and call it like a function, how the basic -> syntax works, when you can use the it parameter, why the result of a lambda is the last expression (and how to accidentally return Unit), and where the compiler needs type hints (for example, (Int) -> Boolean) and which errors occur most often.
    Available
  • Function types and higher-order functions

    Kotlin SELF
    Level 21, Lesson 1
    We break down how to read Kotlin function types like (A) -> B, what a predicate (T) -> Boolean is, why higher-order functions are needed, and how to stop copy-pasting loops by passing “behavior” as a parameter. In practice, we will write our own versions of countMatching, forEachIf, and findFirstOrNull and apply them to a mini expense-tracking project on MutableList with a Triple model.
    Available
  • Callable references :: — passing a named function instead of a lambda

    Kotlin SELF
    Level 21, Lesson 2
    We break down callable references in Kotlin via the :: operator: how to replace a wrapper lambda like { x -> f(x) } with a reference ::f, why it works only with an exact signature match ( (T) -> R), how to store a function reference in a val, and where :: improves readability (predicates, input-processing steps) — with examples and a walkthrough of common mistakes.
    Available
  • Comparison function and Comparator: lambda (T, T) -> Int

    Kotlin SELF
    Level 21, Lesson 3
    We break down the comparison contract via a function of the form ( T , T ) -> Int: why order needs three outcomes (less/equal/greater), how to build a Comparator<T> with the compare method from a lambda, how to apply a comparator to choose the “best” element without sorting, how to do a tie-breaker via return @ Comparator, and why it’s better to write compareTo instead of a - b.
    Available
  • Closures and side effects

    Kotlin SELF
    Level 21, Lesson 4
    We break down closures in Kotlin: how lambdas and local functions capture outer context, how capturing val differs from capturing var, and why an “innocent” predicate like (Int) -> Boolean can suddenly become a source of hidden state and side effects (for example, via println or a counter). At the end: a practical mini-case with Triple and a set of habits that help keep effects visible and local (separating predicate and action, keeping closure lifetimes short).
    Available
Learn
  • Registration
  • Java Course
  • Help with Tasks
  • Pricing
  • Java Syntax
Community
  • Users
  • Articles
  • Forum
  • Chat
  • Success Stories
  • Activity
  • Affiliate Program
Company
  • About us
  • Contacts
  • Reviews
  • Press Room
  • CodeGym for EDU
  • FAQ
  • Support
CodeGym CodeGym is an online course for learning Java programming from scratch. This course is a perfect way to master Java for beginners. It contains 1200+ tasks with instant verification and an essential scope of Java fundamentals theory. To help you succeed in education, we’ve implemented a set of motivational features: quizzes, coding projects, content about efficient learning, and a Java developer’s career.
Follow us
Interface language
English
Deutsch Español हिन्दी Français Português Polski বাংলা 简体中文 मराठी தமிழ் Italiano Bahasa Indonesia 繁體中文 Nederlands 日本語 한국어 Bulgarian Danish Hungarian Basa Jawa Malay Norwegian Romanian Swedish Telugu Thai Українська Filipino Turkish Azərbaycan Русский Vietnamese
Programmers Are Made, Not Born © 2026 CodeGym
MastercardVisa
Programmers Are Made, Not Born © 2026 CodeGym