Better version of "iterate over Seq or if empty" in scala?

playframework-2.0, scala

Solution

How about this?

mySeq.headOption.map { _ =>
  mySeq.map { elmt => 
    // do stuff
  }
}.getOrElse {
  // some other stuff
}

Problem

Is there a shorter/better way to do the following : ``` mySeq.map { elmt => // do stuff } if (mySeq.isEmpty) { // some other stuff } ``` Ps : I'm using PlayFramework and this is meant to be used in templates, so if there are any "helpers" there I missed, I would be glad to discover those ;)

Original source