[Assorted-commits] SF.net SVN: assorted: [749] scala-commons/trunk/src/commons/Collections. scala
Brought to you by:
yangzhang
From: <yan...@us...> - 2008-05-08 19:34:53
|
Revision: 749 http://assorted.svn.sourceforge.net/assorted/?rev=749&view=rev Author: yangzhang Date: 2008-05-08 12:34:26 -0700 (Thu, 08 May 2008) Log Message: ----------- clarified some documentation; fixed splitBy() eagerness bug Modified Paths: -------------- scala-commons/trunk/src/commons/Collections.scala Modified: scala-commons/trunk/src/commons/Collections.scala =================================================================== --- scala-commons/trunk/src/commons/Collections.scala 2008-05-08 19:32:41 UTC (rev 748) +++ scala-commons/trunk/src/commons/Collections.scala 2008-05-08 19:34:26 UTC (rev 749) @@ -317,6 +317,7 @@ /** * Given a list of sublists, return pairs of the first element of each * sublist along with the remaining elements. Empty sublists are ignored. + * Useful in composition with groupByHeaders. * <p> * <code> * separateHeads([[a,b,c],[d,e,f,g],[],[h]]) @@ -399,10 +400,10 @@ * </code> */ def splitBy[a](xs: Seq[a])(pred: a => Boolean): Stream[Seq[a]] = { - val consider = xs dropWhile pred - if (consider.length == 0) { + if (xs.length == 0) { Stream.empty } else { + val consider = xs dropWhile pred val (take, rest) = spanBy(consider)(not(pred)) Stream.cons(take, splitBy(rest)(pred)) } @@ -500,6 +501,8 @@ * predicate. A reverse dropWhile. * <p> * <code>truncateWhile([1,2,3,4,5], (_ != 3)) == [1,2,3]</code> + * <p> + * <code>truncateWhile("!!hello!!", (=='!')) == "!!hello"</code> */ def truncateWhile[a](seq: Seq[a])(pred: a => Boolean) = (seq.reverse dropWhile pred).reverse This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |