The 'takeLast' function is a powerful tool for retrieving a specified number of elements from the end of a collection. This can be particularly useful when you want to access the most recent items in a dataset, such as the latest entries in a log or the most recent messages in a chat application.
val messages = listOf("Hello", "How are you?", "I'm fine, thanks!", "What about you?", "See you soon!")
val recentMessages = messages.takeLast(3)
println(recentMessages) // Output: [I'm fine, thanks!, What about you?, See you soon!]