
For example, we can call our let2() in this way: let2(v1, v2) ).isNull()Īs the assertions show, the letIfAnyNotNull() function will pack all not-null values in a list and pass the list to our lambda expression. In Kotlin, if the last parameter of a function is a function, we can pass a lambda expression to it and put it outside of (…). Miscellaneous features like String Templating from Python or PHP. We execute the block(p1, p2) function only if both p1 and p2 are not null. The function block decides the return type of the let2() function.


block is a function that accepts two not-null arguments and returns a nullable R instance.Īs we can see in the code above, let2() is a generic function, so the two parameters’ ( p1 and p2) types can be different. p1 and p2 are the two nullable parameters.

The function let2() has three parameters: p1, p2, and block.
