Suppose you have a list of lists in Scala,
thing = List( List("a", "AAA", true)
,List("b", "BBB", true)
,List("c", "CCC", true)
,List("d", "DDD", false)
,List("e", "EEE", true) )
And you want to iterate through the list, and use the elements of the inner list for some additional work.
Python would be easy,
foreach x in thing:
if x[2]: func1( x[0], x[1] )
else: func2( x[0], x[1], something_else )
I think this can be roughly translated to scala as something like this,
thing.foreach { x =>
if( x.lift(2) ) func1( x.lift(0), x.lift(1) )
else func2( x.lift(0), x.lift(1), something_else )
}
Is the above idiomatic scala? What is the scala idiom for doing this?