A pure function returns the same result for the same inputs, changes no other object’s state, and does not interact with the outside world. This makes behavior easier to reason about, reuse, and test. section 1.2.3
Pure functions support several practical advantages:
- They reduce reliance on mutable variables, loops, and branching by enabling concise functional abstractions. section 1.2.3
- They help avoid unsafe shared-data modification in concurrent programs when combined with immutable data structures. section 1.2.3
- They can be tested in isolation without constructing the surrounding environment required by code that interacts with the outside world. section 1.2.3
A composed functional pipeline
A Kotlin collection pipeline can express successive operations as function values: messages are filtered, mapped to senders, deduplicated, and sorted. The example illustrates the concise composition associated with functional programming; purity still depends on the behavior of the functions involved. section 1.2.3
A lambda is not automatically pure
A lambda used as a button click handler can print "I was clicked!". Lambda syntax makes behavior concise, but the observable output means the handler is not side-effect-free. section 5.1.1
messages
.filter { it.body.isNotBlank() && !it.isRead }
.map(Message::sender)
.distinct()
.sortedBy(Sender::name)
Browse a compact Kotlin pipeline showing filtering, mapping, deduplication, and sorting as composable operations. section 1.2.3


















