@voddan: Maybe this is slightly clearer?
fun mandelbrot(c: Complex, maxIterations: Int): Int? {
tailrec fun iterate(z: Complex, iterations: Int): Int? = when {
iterations == maxIterations -> null
(z.abs() > 2.0) -> iterations
else -> iterate( (z * z) + c, iterations + 1)
}
return iterate(Complex.zero, 0)
}