title: Converting Seq[T] into Option[Seq[T]]
body: <p>Scala Seq includes methods that are illegal or undefined for an empty sequence, e.g max</p>
  
  <p>To protect myself from this I often address the problem by wrapping the sequence in an option and mapping empty to None. It can be done like this:</p>
  
  <pre><code>def wrap[T](s: Seq[T]): Option[Seq[T]] =
      s.headOption map { _ =&gt; s }
  </code></pre>
  
  <p>It could also be solved by pattern matching or if-else. </p>
  
  <p>None of the approaches are easy to use in a fluent way, and frankly seem a bit awkward. </p>
  
  <p>I would like to be able to do something like this:</p>
  
  <pre><code>someStore
     .giveMeASequence
     .wrapInOption map { nonEmpty:Seq[T] =&gt;
        nonEmpty.max
      } map (_ + 42)
  </code></pre>
  
  <p>I'm hesitant to wrap the operation in the Try monad because the exception can be predicted and avoided. </p>
  
  <p>Am I approaching the problem in the wrong way?</p>
  
  <p>If not, are there any library methods available to me to make it less awkward?</p>