Sobes.tech
Junior — Senior

Checking assert execution when working with scope functions

livecode

Task condition

It needs to be determined whether the assert will be executed in the following code fragment. Pay attention to the differences between using apply and let.

data class Student(val firstName: String, val secondName: String)

fun main() {
    val pupil = Student("Ivan", "Ivanov")

    val newSurname = "Petrov"
    val applied = pupil.apply { Student(firstName, newSurname) }
    val letted = pupil.let { Student(it.firstName, newSurname) }

    assert(applied == letted)
}
Checking assert execution when working with scope… - sobes.tech