Early returns from outer space (in Kotlin)
summary
Kotlin lets a return inside a lambda actually exit the surrounding function because the compiler inlines functions, copying lambda bodies into the call site so returns, breaks and continues behave like native control flow. The code example builds a first-contact scenario with ships, nullable commanders and carbon-based aliens and shows smart casts refining types after early returns so properties like origin are accessible without casts. This works for collection ops and resource helpers but increases code size, so use inlining selectively.
AI-written summary Β· about
chapters (10)
- 0:00Introduction to Kotlin talk
- 1:25Expression-based bodies in Kotlin
- 2:29Why early returns matter
- 3:11Domain model for alien contact
- 5:55Smart casting explained
- 8:23Advantages of smart casting
- 9:25Early returns with crew contact
- 10:49Inline functions and control flow
- 13:14Summary of Kotlin features
- 13:57Q&A on inline functions
