Two thoughts:
1.) I doubt that getInnerPolygons is tail recursive, because the recursive call to getInnerPolygons within flatMap is not the last statement to be executed. This is flatMap itself (but I may be wrong). Recursive calls to functions which are not tail recursive can lead to a stack overflow, when recursion is going deeper. In this case recursion can't be eliminated by the compiler.
2.) You could write
(0 to geometry.GetGeometryCount())
I doubt that
getInnerPolygonsis tail recursive, because the recursive call togetInnerPolygonswithinflatMapis not the last statement to be executed. This isflatMapitself (but I may be wrong). Recursive calls to functions which are not tail recursive can lead to a stack overflow, when recursion is going deeper. In this case recursion can't be eliminated by the compiler.You could write
(0 to geometry.GetGeometryCount())
instead of
Iterator.range(0, geometry.GetGeometryCount())
to create a range. This is slightly shorter.