The 'with' function in Kotlin allows you to perform multiple operations on a single object without repeating the object reference. This can lead to cleaner and more readable code, especially when working with complex objects or performing multiple configurations.
val user = User("John", "Doe").apply {
age = 30
email = "john.doe@example.com"
}
with(user) {
println("User's full name is $firstName $lastName")
println("User's age is $age")
println("User's email is $email")
}