|
Scala example source code file (SeqExtractors.scala)
The SeqExtractors.scala Scala example source codepackage scala package 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. * @return 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) } // Dummy to fool ant private abstract class SeqExtractors Other Scala source code examplesHere is a short list of links related to this Scala SeqExtractors.scala source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.