title: How to write it idiomatically in Scala?
body: <p>Suppose I have a function to check a string:</p>
  
  <pre><code>case class MyError(msg: String)
  val oops = MyError("oops")
  
  def validate(s: String):Either[MyError, Unit] = 
    if (s == "a") Right(()) else Left(oops)
  </code></pre>
  
  <p>Now I would like to reuse it and write a new function to check the head of a list of strings and return either an error or the list tail.</p>
  
  <pre><code>// should be validateHeadOfList but I don't want to change the name now 
  
  def validateList(xs: List[String]): Either[MyError, List[String]] = 
    xs match { 
      case head::tail =&gt; 
        validate(head).fold(err =&gt; Left(err), _ =&gt; Right(tail))
      case _ =&gt; Left(oops)
    }
  </code></pre>
  
  <p>This function works but doesn't look elegant. How would you improve it ?</p>