Convert indexing to Scala