summaryrefslogblamecommitdiff
path: root/src/library/scala/collection/SeqExtractors.scala
blob: cb3cb27f188fad9cca908f352ceb60ce01a9dfb6 (plain) (tree)




















                                                            
package scala.collection

/** An extractor used to head/tail deconstruct sequences. */
object +: {
  def unapply[T,Coll <: SeqLike[T, Coll]](
      t: Coll with SeqLike[T, Coll]): Option[(T, Coll)] =
    if(t.isEmpty) None
    else Some(t.head -> t.tail)
}

/** An extractor used to init/last deconstruct sequences. */
object :+ {
  /** Splits a sequence into init :+ tail.
   * @returns Some(init, tail) if sequence is non-empty.
   *          None otherwise.
   */
  def unapply[T,Coll <: SeqLike[T, Coll]](
      t: Coll with SeqLike[T, Coll]): Option[(Coll, T)] =
    if(t.isEmpty) None
    else Some(t.init -> t.last)
}