Skip to content

Commit 9c2aaa7

Browse files
committed
Improve doc of dropWhile
1 parent a6718a3 commit 9c2aaa7

File tree

3 files changed

+47
-8
lines changed

3 files changed

+47
-8
lines changed

library/src/scala/collection/Iterable.scala

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -420,12 +420,14 @@ trait IterableOps[+A, +CC[_], +C] extends Any with IterableOnce[A] with Iterable
420420
def withFilter(p: A => Boolean): collection.WithFilter[A, CC] = new IterableOps.WithFilter(this, p)
421421

422422
/** A pair of, first, all elements that satisfy predicate `p` and, second,
423-
* all elements that do not. Interesting because it splits a collection in two.
424-
*
425-
* The default implementation provided here needs to traverse the collection twice.
426-
* Strict collections have an overridden version of `partition` in `StrictOptimizedIterableOps`,
427-
* which requires only a single traversal.
428-
*/
423+
* all elements that do not.
424+
*
425+
* The two $coll correspond to the result of [[filter]] and [[filterNot]], respectively.
426+
*
427+
* The default implementation provided here needs to traverse the collection twice.
428+
* Strict collections have an overridden version of `partition` in `StrictOptimizedIterableOps`,
429+
* which requires only a single traversal.
430+
*/
429431
def partition(p: A => Boolean): (C, C) = {
430432
val first = new View.Filter(this, p, false)
431433
val second = new View.Filter(this, p, true)

library/src/scala/collection/IterableOnce.scala

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,24 @@ trait IterableOnceOps[+A, +CC[_], +C] extends Any { this: IterableOnce[A] =>
357357
def take(n: Int): C
358358

359359
/** Takes longest prefix of elements that satisfy a predicate.
360+
*
361+
* The matching prefix starts with the first element of this $coll,
362+
* and the element following the prefix is the first element that
363+
* does not satisfy the predicate. The matching prefix may empty,
364+
* so that this method returns an empty $coll.
365+
*
366+
* Example:
367+
*
368+
* {{{
369+
* scala> List(1, 2, 3, 100, 4).takeWhile(n => n < 10)
370+
* val res0: List[Int] = List(1, 2, 3)
371+
*
372+
* scala> List(1, 2, 3, 100, 4).takeWhile(n => n == 0)
373+
* val res1: List[Int] = List()
374+
* }}}
375+
*
376+
* Use [[span]] to obtain both the prefix and suffix.
377+
* Use [[filter]] to retain only those elements from the entire $coll that satisfy the predicate.
360378
* $orderDependent
361379
* @param p The predicate used to test elements.
362380
* @return the longest prefix of this $coll whose elements all satisfy
@@ -374,6 +392,25 @@ trait IterableOnceOps[+A, +CC[_], +C] extends Any { this: IterableOnce[A] =>
374392
def drop(n: Int): C
375393

376394
/** Drops longest prefix of elements that satisfy a predicate.
395+
*
396+
* The matching prefix starts with the first element of this $coll,
397+
* and the element following the prefix is the first element that
398+
* does not satisfy the predicate. The matching prefix may empty,
399+
* so that this method returns the entire $coll.
400+
*
401+
* Example:
402+
*
403+
* {{{
404+
* scala> List(1, 2, 3, 100, 4).dropWhile(n => n < 10)
405+
* val res0: List[Int] = List(100, 4)
406+
*
407+
* scala> List(1, 2, 3, 100, 4).dropWhile(n => n == 0)
408+
* val res1: List[Int] = List(1, 2, 3, 100, 4)
409+
* }}}
410+
*
411+
* Use [[span]] to obtain both the prefix and suffix.
412+
* Use [[filterNot]] to drop all elements that satisfy the predicate.
413+
*
377414
* $orderDependent
378415
* @param p The predicate used to test elements.
379416
* @return the longest suffix of this $coll whose first element

library/src/scala/language.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ object language {
104104
* non-implicit parameter. Examples:
105105
*
106106
* {{{
107-
* implicit def intToString(i: Int): String = s"$i"
108-
* implicit val conv: Int => String = i => s"$i"
107+
* implicit def intToString(i: Int): String = s"\$i"
108+
* implicit val conv: Int => String = i => s"\$i"
109109
* implicit val numerals: List[String] = List("zero", "one", "two", "three")
110110
* implicit val strlen: String => Int = _.length
111111
* implicit def listToInt[T](xs: List[T])(implicit f: T => Int): Int = xs.map(f).sum

0 commit comments

Comments
 (0)