Gopal S Akshintala
07/14/2020, 4:07 PMtailrec fun TreeNode.findMin(): TreeNode = left?.findMin() ?: this
But this is: tailrec fun TreeNode.findMin(): TreeNode = if (left == null) this else left!!.findMin()
I am missing the concise syntax, why can’t the compiler smartly make the first one tailrec
Casey Brooks
07/14/2020, 4:15 PM.findMin()
in the first example, because nulls get passed all the way through the call chain. In the second example, the null-check there is before the call to .findMin()
, so findMin()
actually is the last call being madepedro
07/14/2020, 5:01 PM