Skip to content

Commit 1b87eb6

Browse files
authored
Merge pull request scala/scala#10616 from shardulc/scaladoc/list-consistency
Make `List` documentation more consistent
2 parents ded003b + cac8d0b commit 1b87eb6

File tree

6 files changed

+87
-45
lines changed

6 files changed

+87
-45
lines changed

library/src/scala/Equals.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ package scala
1616
* The only method not already present in class `AnyRef` is `canEqual`.
1717
*/
1818
trait Equals extends Any {
19-
/** A method that should be called from every well-designed equals method
19+
/** Checks whether this instance can possibly equal `that`.
20+
*
21+
* A method that should be called from every well-designed equals method
2022
* that is open to be overridden in a subclass. See
2123
* [[https://www.artima.com/pins1ed/object-equality.html Programming in Scala,
2224
* Chapter 28]] for discussion and design.
@@ -26,7 +28,8 @@ trait Equals extends Any {
2628
*/
2729
def canEqual(that: Any): Boolean
2830

29-
/** The universal equality method defined in `AnyRef`.
31+
/** Checks whether this instance is equal to `that`.
32+
* This universal equality method is defined in `AnyRef`.
3033
*/
3134
def equals(that: Any): Boolean
3235
}

library/src/scala/Function1.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,15 @@ trait Function1[@specialized(Specializable.Arg) -T1, @specialized(Specializable.
7070
*/
7171
def apply(v1: T1): R
7272

73-
/** Composes two instances of Function1 in a new Function1, with this function applied last.
73+
/** Composes two instances of `Function1` in a new `Function1`, with this function applied last.
7474
*
7575
* @tparam A the type to which function `g` can be applied
7676
* @param g a function A => T1
7777
* @return a new function `f` such that `f(x) == apply(g(x))`
7878
*/
7979
@annotation.unspecialized def compose[A](g: A => T1): A => R = { x => apply(g(x)) }
8080

81-
/** Composes two instances of Function1 in a new Function1, with this function applied first.
81+
/** Composes two instances of `Function1` in a new `Function1`, with this function applied first.
8282
*
8383
* @tparam A the result type of function `g`
8484
* @param g a function R => A

library/src/scala/collection/Iterable.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ trait IterableOps[+A, +CC[_], +C] extends Any with IterableOnce[A] with Iterable
208208
*/
209209
protected def newSpecificBuilder: Builder[A @uncheckedVariance, C]
210210

211-
/** The empty iterable of the same type as this iterable
211+
/** The empty iterable of the same type as this iterable.
212212
*
213213
* @return an empty iterable of type `C`.
214214
*/
@@ -481,7 +481,7 @@ trait IterableOps[+A, +CC[_], +C] extends Any with IterableOnce[A] with Iterable
481481
iterator.grouped(size).map(fromSpecific)
482482

483483
/** Groups elements in fixed size blocks by passing a "sliding window"
484-
* over them (as opposed to partitioning them, as is done in `grouped`.)
484+
* over them (as opposed to partitioning them, as is done in `grouped`).
485485
*
486486
* An empty collection returns an empty iterator, and a non-empty
487487
* collection containing fewer elements than the window size returns
@@ -502,7 +502,7 @@ trait IterableOps[+A, +CC[_], +C] extends Any with IterableOnce[A] with Iterable
502502
def sliding(size: Int): Iterator[C] = sliding(size, 1)
503503

504504
/** Groups elements in fixed size blocks by passing a "sliding window"
505-
* over them (as opposed to partitioning them, as is done in grouped.)
505+
* over them (as opposed to partitioning them, as is done in `grouped`).
506506
*
507507
* The returned iterator will be empty when called on an empty collection.
508508
* The last element the iterator produces may be smaller than the window

library/src/scala/collection/IterableOnce.scala

Lines changed: 63 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,13 @@ import scala.runtime.{AbstractFunction1, AbstractFunction2}
4242
* @define coll collection
4343
*/
4444
trait IterableOnce[+A] extends Any {
45-
/** Iterator can be used only once */
45+
46+
/** An [[scala.collection.Iterator]] over the elements of this $coll.
47+
*
48+
* If an `IterableOnce` object is in fact an [[scala.collection.Iterator]], this method always returns itself,
49+
* in its current state, but if it is an [[scala.collection.Iterable]], this method always returns a new
50+
* [[scala.collection.Iterator]].
51+
*/
4652
def iterator: Iterator[A]
4753

4854
/** Returns a [[scala.collection.Stepper]] for the elements of this collection.
@@ -76,7 +82,7 @@ trait IterableOnce[+A] extends Any {
7682
s.asInstanceOf[S]
7783
}
7884

79-
/** @return The number of elements in this $coll, if it can be cheaply computed,
85+
/** The number of elements in this $coll, if it can be cheaply computed,
8086
* -1 otherwise. Cheaply usually means: Not requiring a collection traversal.
8187
*/
8288
def knownSize: Int = -1
@@ -347,7 +353,7 @@ trait IterableOnceOps[+A, +CC[_], +C] extends Any { this: IterableOnce[A] =>
347353
*/
348354
def filterNot(pred: A => Boolean): C
349355

350-
/** Selects the first ''n'' elements.
356+
/** Selects the first `n` elements.
351357
* $orderDependent
352358
* @param n the number of elements to take from this $coll.
353359
* @return a $coll consisting only of the first `n` elements of this $coll,
@@ -356,7 +362,7 @@ trait IterableOnceOps[+A, +CC[_], +C] extends Any { this: IterableOnce[A] =>
356362
*/
357363
def take(n: Int): C
358364

359-
/** Takes longest prefix of elements that satisfy a predicate.
365+
/** Selects the longest prefix of elements that satisfy a predicate.
360366
*
361367
* The matching prefix starts with the first element of this $coll,
362368
* and the element following the prefix is the first element that
@@ -382,7 +388,7 @@ trait IterableOnceOps[+A, +CC[_], +C] extends Any { this: IterableOnce[A] =>
382388
*/
383389
def takeWhile(p: A => Boolean): C
384390

385-
/** Selects all elements except first ''n'' ones.
391+
/** Selects all elements except the first `n` ones.
386392
* $orderDependent
387393
* @param n the number of elements to drop from this $coll.
388394
* @return a $coll consisting of all elements of this $coll except the first `n` ones, or else the
@@ -391,7 +397,7 @@ trait IterableOnceOps[+A, +CC[_], +C] extends Any { this: IterableOnce[A] =>
391397
*/
392398
def drop(n: Int): C
393399

394-
/** Drops longest prefix of elements that satisfy a predicate.
400+
/** Selects all elements except the longest prefix that satisfies a predicate.
395401
*
396402
* The matching prefix starts with the first element of this $coll,
397403
* and the element following the prefix is the first element that
@@ -605,8 +611,8 @@ trait IterableOnceOps[+A, +CC[_], +C] extends Any { this: IterableOnce[A] =>
605611
*/
606612
def isTraversableAgain: Boolean = false
607613

608-
/** Apply `f` to each element for its side effects
609-
* Note: [U] parameter needed to help scalac's type inference.
614+
/** Applies `f` to each element for its side effects.
615+
* Note: `U` parameter needed to help scalac's type inference.
610616
*/
611617
def foreach[U](f: A => U): Unit = {
612618
val it = iterator
@@ -907,7 +913,7 @@ trait IterableOnceOps[+A, +CC[_], +C] extends Any { this: IterableOnce[A] =>
907913
@deprecated("Use `dest ++= coll` instead", "2.13.0")
908914
@inline final def copyToBuffer[B >: A](dest: mutable.Buffer[B]): Unit = dest ++= this
909915

910-
/** Copy elements to an array, returning the number of elements written.
916+
/** Copies elements to an array, returning the number of elements written.
911917
*
912918
* Fills the given array `xs` starting at index `start` with values of this $coll.
913919
*
@@ -923,7 +929,7 @@ trait IterableOnceOps[+A, +CC[_], +C] extends Any { this: IterableOnce[A] =>
923929
@deprecatedOverriding("This should always forward to the 3-arg version of this method", since = "2.13.4")
924930
def copyToArray[B >: A](xs: Array[B]): Int = copyToArray(xs, 0, Int.MaxValue)
925931

926-
/** Copy elements to an array, returning the number of elements written.
932+
/** Copies elements to an array, returning the number of elements written.
927933
*
928934
* Fills the given array `xs` starting at index `start` with values of this $coll.
929935
*
@@ -1067,15 +1073,15 @@ trait IterableOnceOps[+A, +CC[_], +C] extends Any { this: IterableOnce[A] =>
10671073
case _ => Some(reduceLeft(ord.max))
10681074
}
10691075

1070-
/** Finds the first element which yields the largest value measured by function f.
1076+
/** Finds the first element which yields the largest value measured by function `f`.
10711077
*
10721078
* $willNotTerminateInf
10731079
*
10741080
* @param cmp An ordering to be used for comparing elements.
1075-
* @tparam B The result type of the function f.
1081+
* @tparam B The result type of the function `f`.
10761082
* @param f The measuring function.
10771083
* @throws UnsupportedOperationException if this $coll is empty.
1078-
* @return the first element of this $coll with the largest value measured by function f
1084+
* @return the first element of this $coll with the largest value measured by function `f`
10791085
* with respect to the ordering `cmp`.
10801086
*/
10811087
def maxBy[B](f: A => B)(implicit ord: Ordering[B]): A =
@@ -1107,31 +1113,31 @@ trait IterableOnceOps[+A, +CC[_], +C] extends Any { this: IterableOnce[A] =>
11071113
}
11081114
}
11091115

1110-
/** Finds the first element which yields the largest value measured by function f.
1116+
/** Finds the first element which yields the largest value measured by function `f`.
11111117
*
11121118
* $willNotTerminateInf
11131119
*
11141120
* @param cmp An ordering to be used for comparing elements.
1115-
* @tparam B The result type of the function f.
1121+
* @tparam B The result type of the function `f`.
11161122
* @param f The measuring function.
11171123
* @return an option value containing the first element of this $coll with the
1118-
* largest value measured by function f with respect to the ordering `cmp`.
1124+
* largest value measured by function `f` with respect to the ordering `cmp`.
11191125
*/
11201126
def maxByOption[B](f: A => B)(implicit ord: Ordering[B]): Option[A] =
11211127
knownSize match {
11221128
case 0 => None
11231129
case _ => foldLeft(new Maximized[A, B]("maxBy")(f)(ord.gt))((m, a) => m(m, a)).toOption
11241130
}
11251131

1126-
/** Finds the first element which yields the smallest value measured by function f.
1132+
/** Finds the first element which yields the smallest value measured by function `f`.
11271133
*
11281134
* $willNotTerminateInf
11291135
*
11301136
* @param cmp An ordering to be used for comparing elements.
1131-
* @tparam B The result type of the function f.
1137+
* @tparam B The result type of the function `f`.
11321138
* @param f The measuring function.
11331139
* @throws UnsupportedOperationException if this $coll is empty.
1134-
* @return the first element of this $coll with the smallest value measured by function f
1140+
* @return the first element of this $coll with the smallest value measured by function `f`
11351141
* with respect to the ordering `cmp`.
11361142
*/
11371143
def minBy[B](f: A => B)(implicit ord: Ordering[B]): A =
@@ -1140,15 +1146,15 @@ trait IterableOnceOps[+A, +CC[_], +C] extends Any { this: IterableOnce[A] =>
11401146
case _ => foldLeft(new Maximized[A, B]("minBy")(f)(ord.lt))((m, a) => m(m, a)).result
11411147
}
11421148

1143-
/** Finds the first element which yields the smallest value measured by function f.
1149+
/** Finds the first element which yields the smallest value measured by function `f`.
11441150
*
11451151
* $willNotTerminateInf
11461152
*
11471153
* @param cmp An ordering to be used for comparing elements.
1148-
* @tparam B The result type of the function f.
1154+
* @tparam B The result type of the function `f`.
11491155
* @param f The measuring function.
11501156
* @return an option value containing the first element of this $coll
1151-
* with the smallest value measured by function f
1157+
* with the smallest value measured by function `f`
11521158
* with respect to the ordering `cmp`.
11531159
*/
11541160
def minByOption[B](f: A => B)(implicit ord: Ordering[B]): Option[A] =
@@ -1335,7 +1341,7 @@ trait IterableOnceOps[+A, +CC[_], +C] extends Any { this: IterableOnce[A] =>
13351341
*/
13361342
@inline final def addString(b: StringBuilder): b.type = addString(b, "")
13371343

1338-
/** Given a collection factory `factory`, convert this collection to the appropriate
1344+
/** Given a collection factory `factory`, converts this $coll to the appropriate
13391345
* representation for the current element type `A`. Example uses:
13401346
*
13411347
* {{{
@@ -1349,29 +1355,61 @@ trait IterableOnceOps[+A, +CC[_], +C] extends Any { this: IterableOnce[A] =>
13491355
@deprecated("Use .iterator instead of .toIterator", "2.13.0")
13501356
@`inline` final def toIterator: Iterator[A] = iterator
13511357

1358+
/** Converts this $coll to a `List`.
1359+
*
1360+
* @return This $coll as a `List[A]`.
1361+
*/
13521362
def toList: immutable.List[A] = immutable.List.from(this)
13531363

1364+
/** Converts this $coll to a `Vector`.
1365+
*
1366+
* @return This $coll as a `Vector[A]`.
1367+
*/
13541368
def toVector: immutable.Vector[A] = immutable.Vector.from(this)
13551369

1370+
/** Converts this $coll to a `Map`, given an implicit coercion from the $coll's type to a key-value tuple.
1371+
*
1372+
* @tparam K The key type for the resulting map.
1373+
* @tparam V The value type for the resulting map.
1374+
* @param ev An implicit coercion from `A` to `[K, V]`.
1375+
* @return This $coll as a `Map[K, V]`.
1376+
*/
13561377
def toMap[K, V](implicit ev: A <:< (K, V)): immutable.Map[K, V] =
13571378
immutable.Map.from(this.asInstanceOf[IterableOnce[(K, V)]])
13581379

1380+
/** Converts this $coll to a `Set`.
1381+
*
1382+
* @tparam B The type of elements of the result, a supertype of `A`.
1383+
* @return This $coll as a `Set[B]`.
1384+
*/
13591385
def toSet[B >: A]: immutable.Set[B] = immutable.Set.from(this)
13601386

1361-
/** @return This collection as a `Seq[A]`. This is equivalent to `to(Seq)` but might be faster.
1387+
/** @return This $coll as a `Seq[A]`. This is equivalent to `to(Seq)` but might be faster.
13621388
*/
13631389
def toSeq: immutable.Seq[A] = immutable.Seq.from(this)
13641390

1391+
/** Converts this $coll to an `IndexedSeq`.
1392+
*
1393+
* @return This $coll as an `IndexedSeq[A]`.
1394+
*/
13651395
def toIndexedSeq: immutable.IndexedSeq[A] = immutable.IndexedSeq.from(this)
13661396

13671397
@deprecated("Use .to(LazyList) instead of .toStream", "2.13.0")
13681398
@inline final def toStream: immutable.Stream[A] = to(immutable.Stream)
13691399

1400+
/** Converts this $coll to a `Buffer`.
1401+
*
1402+
* @tparam B The type of elements of the result, a supertype of `A`.
1403+
* @return This $coll as a `Buffer[B]`.
1404+
*/
13701405
@inline final def toBuffer[B >: A]: mutable.Buffer[B] = mutable.Buffer.from(this)
13711406

1372-
/** Convert collection to array.
1407+
/** Converts this $coll to an `Array`.
13731408
*
13741409
* Implementation note: DO NOT call [[Array.from]] from this method.
1410+
*
1411+
* @tparam B The type of elements of the result, a supertype of `A`.
1412+
* @return This $coll as an `Array[B]`.
13751413
*/
13761414
def toArray[B >: A: ClassTag]: Array[B] =
13771415
if (knownSize >= 0) {

library/src/scala/collection/Seq.scala

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ trait SeqOps[+A, +CC[_], +C] extends Any
7979

8080
override def view: SeqView[A] = new SeqView.Id[A](this)
8181

82-
/** Get the element at the specified index. This operation is provided for convenience in `Seq`. It should
82+
/** Gets the element at the specified index. This operation is provided for convenience in `Seq`. It should
8383
* not be assumed to be efficient unless you have an `IndexedSeq`. */
8484
@throws[IndexOutOfBoundsException]
8585
def apply(i: Int): A
@@ -141,7 +141,7 @@ trait SeqOps[+A, +CC[_], +C] extends Any
141141
*/
142142
def appended[B >: A](elem: B): CC[B] = iterableFactory.from(new View.Appended(this, elem))
143143

144-
/** Alias for `appended`
144+
/** Alias for `appended`.
145145
*
146146
* Note that :-ending operators are right associative (see example).
147147
* A mnemonic for `+:` vs. `:+` is: the COLon goes on the COLlection side.
@@ -165,7 +165,7 @@ trait SeqOps[+A, +CC[_], +C] extends Any
165165
case _ => prefix.iterator ++ iterator
166166
})
167167

168-
/** Alias for `prependedAll` */
168+
/** Alias for `prependedAll`. */
169169
@`inline` override final def ++: [B >: A](prefix: IterableOnce[B]): CC[B] = prependedAll(prefix)
170170

171171
/** Returns a new $coll containing the elements from the left hand operand followed by the elements from the
@@ -179,7 +179,7 @@ trait SeqOps[+A, +CC[_], +C] extends Any
179179
*/
180180
def appendedAll[B >: A](suffix: IterableOnce[B]): CC[B] = super.concat(suffix)
181181

182-
/** Alias for `appendedAll` */
182+
/** Alias for `appendedAll`. */
183183
@`inline` final def :++ [B >: A](suffix: IterableOnce[B]): CC[B] = appendedAll(suffix)
184184

185185
// Make `concat` an alias for `appendedAll` so that it benefits from performance
@@ -214,22 +214,22 @@ trait SeqOps[+A, +CC[_], +C] extends Any
214214
*/
215215
def distinctBy[B](f: A => B): C = fromSpecific(new View.DistinctBy(this, f))
216216

217-
/** Returns new $coll with elements in reversed order.
217+
/** Returns a new $coll with the elements of this $coll in reverse order.
218218
*
219219
* $willNotTerminateInf
220220
* $willForceEvaluation
221221
*
222-
* @return A new $coll with all elements of this $coll in reversed order.
222+
* @return a new $coll with all elements of this $coll in reverse order.
223223
*/
224224
def reverse: C = fromSpecific(reversed)
225225

226-
/** An iterator yielding elements in reversed order.
226+
/** An iterator yielding the elements of this $coll in reverse order.
227227
*
228228
* $willNotTerminateInf
229229
*
230230
* Note: `xs.reverseIterator` is the same as `xs.reverse.iterator` but might be more efficient.
231231
*
232-
* @return an iterator yielding the elements of this $coll in reversed order
232+
* @return an iterator yielding the elements of this $coll in reverse order.
233233
*/
234234
def reverseIterator: Iterator[A] = reversed.iterator
235235

@@ -843,8 +843,8 @@ trait SeqOps[+A, +CC[_], +C] extends Any
843843

844844
override def isEmpty: Boolean = lengthCompare(0) == 0
845845

846-
/** Are the elements of this collection the same (and in the same order)
847-
* as those of `that`?
846+
/** Tests whether the elements of this collection are the same (and in the same order)
847+
* as those of `that`.
848848
*/
849849
def sameElements[B >: A](that: IterableOnce[B]): Boolean = {
850850
val thisKnownSize = knownSize
@@ -966,7 +966,7 @@ trait SeqOps[+A, +CC[_], +C] extends Any
966966
occ
967967
}
968968

969-
/** Search this sorted sequence for a specific element. If the sequence is an
969+
/** Searches this sorted sequence for a specific element. If the sequence is an
970970
* `IndexedSeq`, a binary search is used. Otherwise, a linear search is used.
971971
*
972972
* The sequence should be sorted with the same `Ordering` before calling; otherwise,
@@ -986,7 +986,7 @@ trait SeqOps[+A, +CC[_], +C] extends Any
986986
def search[B >: A](elem: B)(implicit ord: Ordering[B]): SearchResult =
987987
linearSearch(view, elem, 0)(ord)
988988

989-
/** Search within an interval in this sorted sequence for a specific element. If this
989+
/** Searches within an interval in this sorted sequence for a specific element. If this
990990
* sequence is an `IndexedSeq`, a binary search is used. Otherwise, a linear search
991991
* is used.
992992
*

0 commit comments

Comments
 (0)