Is this a correct recursive Scala iterator creation? I am diving into Scala (using 2.10) headfirst and am trying out a simple task of taking bulk data and then doing something with that stream. The first part is generating that stream. I have seem to be able to cobble together what seems to work, but I think I am missing shortcuts in scala. Any pointers or code cleanup recommendations are welcome! I feel like getInnerPolygons could be simplified using a match statement, but I haven't gotten my head around those yet.

So, the process: With gdal, you retrieve a dataset, then retrieve the layer. From the layer, you can iterate over the features. From those features, you can get the geometries from each feature. Now, most features are just one polygon. If it is, take the outer ring of that polygon and pass it up the line. If the polygon is multi-part (think the hawaii islands as one "feature" where each island is a polygon), retrieve the polygons, then split that into their individual outer rings (this is that recursive call into getInnerPolygons).

Again: any Scala best practices or shortcuts that I missed. I would love to hear about.

def getInnerPolygons(geometry: Geometry) : Iterator[Geometry] = {
    Iterator
        .range(0,geometry.GetGeometryCount())
        .flatMap(i=&gt;{
            val innerGeometry = geometry.GetGeometryRef(i)
            if(innerGeometry.GetGeometryName().equals("LINEARRING"))
                Iterator.single(innerGeometry)
            else
                getInnerPolygons(innerGeometry)
       })
}

def getPolygons(layer : Layer) : Iterator[Geometry] = {
    Iterator.continually[Feature](layer.GetNextFeature())
        .takeWhile(_!=null)
        .flatMap(feature=&gt;getInnerPolygons(feature.GetGeometryRef()))
}  

def main(args: Array[String]){
    ogr.RegisterAll()

    val dataSet = ogr.Open("myshapefile.shp")
    val layer = dataSet.GetLayer(0)

    for(i &lt;- getPolygons(layer)) println(i.GetGeometryName())

    println("Done")
}
micro changes:
use == instead of equals because "==" means "equals".

Scala does not follow the Java convention of prepending set/get to mutator and accessor methods.

Try to split different parts of work (abstraction)

def innerPolygons(geometry: Geometry) : Iterator[Geometry] =
  innerGeometry(geometry).flatMap(inner)

def innerGeometry(geometry: Geometry): Iterator[Geometry]=
  (0 to geometry.GetGeometryCount()).map(geometry.GetGeometryRef(_))

def inner:Geometry =&gt; Iterator = g =&gt; if ("LINEARRING"== g.GetGeometryName()) 
  Iterator.single(g) 
 else            
  innerPolygons(g)