samedi 14 mars 2020

Scala: seq.size vs pattern matching

I have to make a decision based on size of a Seq.

So, either I can do:

if(mySeq.size() > 0) // do your stuff

Or, I can do:

mySeq match {
  case x :: _ => // do your stuff
}

Which one should I prefer?

Aucun commentaire:

Enregistrer un commentaire