Skip to content

Commit dfdd7fd

Browse files
committed
Use ccoll and align margins
1 parent a859e38 commit dfdd7fd

File tree

9 files changed

+217
-218
lines changed

9 files changed

+217
-218
lines changed

library/src/scala/collection/Iterable.scala

Lines changed: 98 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ trait Iterable[+A] extends IterableOnce[A]
127127
* @define willNotTerminateInf
128128
*
129129
* Note: will not terminate for infinite-sized collections.
130-
* @define undefinedorder
130+
* @define undefinedorder
131131
* The order in which operations are performed on elements is unspecified
132132
* and may be nondeterministic.
133133
*/
@@ -140,9 +140,9 @@ trait IterableOps[+A, +CC[_], +C] extends Any with IterableOnce[A] with Iterable
140140
def toIterable: Iterable[A]
141141

142142
/** Converts this $coll to an unspecified Iterable. Will return
143-
* the same collection if this instance is already Iterable.
144-
* @return An Iterable containing all elements of this $coll.
145-
*/
143+
* the same collection if this instance is already Iterable.
144+
* @return An Iterable containing all elements of this $coll.
145+
*/
146146
@deprecated("toTraversable is internal and will be made protected; its name is similar to `toList` or `toSeq`, but it doesn't copy non-immutable collections", "2.13.0")
147147
final def toTraversable: Traversable[A] = toIterable
148148

@@ -208,24 +208,24 @@ 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 $coll.
212212
*
213-
* @return an empty iterable of type `C`.
213+
* @return an empty iterable of type $Coll.
214214
*/
215215
def empty: C = fromSpecific(Nil)
216216

217217
/** Selects the first element of this $coll.
218-
* $orderDependent
219-
* @return the first element of this $coll.
220-
* @throws NoSuchElementException if the $coll is empty.
221-
*/
218+
* $orderDependent
219+
* @return the first element of this $coll.
220+
* @throws NoSuchElementException if the $coll is empty.
221+
*/
222222
def head: A = iterator.next()
223223

224224
/** Optionally selects the first element.
225-
* $orderDependent
226-
* @return the first element of this $coll if it is nonempty,
227-
* `None` if it is empty.
228-
*/
225+
* $orderDependent
226+
* @return the first element of this $coll if it is nonempty,
227+
* `None` if it is empty.
228+
*/
229229
def headOption: Option[A] = {
230230
val it = iterator
231231
if (it.hasNext) Some(it.next()) else None
@@ -244,32 +244,32 @@ trait IterableOps[+A, +CC[_], +C] extends Any with IterableOnce[A] with Iterable
244244
}
245245

246246
/** Optionally selects the last element.
247-
* $orderDependent
248-
* @return the last element of this $coll$ if it is nonempty,
249-
* `None` if it is empty.
250-
*/
247+
* $orderDependent
248+
* @return the last element of this $coll if it is nonempty,
249+
* `None` if it is empty.
250+
*/
251251
def lastOption: Option[A] = if (isEmpty) None else Some(last)
252252

253253
/** A view over the elements of this collection. */
254254
def view: View[A] = View.fromIteratorProvider(() => iterator)
255255

256256
/** Compares the size of this $coll to a test value.
257-
*
258-
* @param otherSize the test value that gets compared with the size.
259-
* @return A value `x` where
260-
* {{{
261-
* x < 0 if this.size < otherSize
262-
* x == 0 if this.size == otherSize
263-
* x > 0 if this.size > otherSize
264-
* }}}
265-
*
266-
* The method as implemented here does not call `size` directly; its running time
267-
* is `O(size min otherSize)` instead of `O(size)`. The method should be overridden
268-
* if computing `size` is cheap and `knownSize` returns `-1`.
269-
*
270-
* @see [[sizeIs]]
271-
*/
272-
def sizeCompare(otherSize: Int): Int = {
257+
*
258+
* @param otherSize the test value that gets compared with the size.
259+
* @return A value `x` where
260+
* {{{
261+
* x < 0 if this.size < otherSize
262+
* x == 0 if this.size == otherSize
263+
* x > 0 if this.size > otherSize
264+
* }}}
265+
*
266+
* The method as implemented here does not call `size` directly; its running time
267+
* is `O(size min otherSize)` instead of `O(size)`. The method should be overridden
268+
* if computing `size` is cheap and `knownSize` returns `-1`.
269+
*
270+
* @see [[sizeIs]]
271+
*/
272+
def sizeCompare(otherSize: Int): Int =
273273
if (otherSize < 0) 1
274274
else {
275275
val known = knownSize
@@ -285,7 +285,6 @@ trait IterableOps[+A, +CC[_], +C] extends Any with IterableOnce[A] with Iterable
285285
i - otherSize
286286
}
287287
}
288-
}
289288

290289
/** Returns a value class containing operations for comparing the size of this $coll to a test value.
291290
*
@@ -304,19 +303,19 @@ trait IterableOps[+A, +CC[_], +C] extends Any with IterableOnce[A] with Iterable
304303
@inline final def sizeIs: IterableOps.SizeCompareOps = new IterableOps.SizeCompareOps(this)
305304

306305
/** Compares the size of this $coll to the size of another `Iterable`.
307-
*
308-
* @param that the `Iterable` whose size is compared with this $coll's size.
309-
* @return A value `x` where
310-
* {{{
311-
* x < 0 if this.size < that.size
312-
* x == 0 if this.size == that.size
313-
* x > 0 if this.size > that.size
314-
* }}}
315-
*
316-
* The method as implemented here does not call `size` directly; its running time
317-
* is `O(this.size min that.size)` instead of `O(this.size + that.size)`.
318-
* The method should be overridden if computing `size` is cheap and `knownSize` returns `-1`.
319-
*/
306+
*
307+
* @param that the `Iterable` whose size is compared with this $coll's size.
308+
* @return A value `x` where
309+
* {{{
310+
* x < 0 if this.size < that.size
311+
* x == 0 if this.size == that.size
312+
* x > 0 if this.size > that.size
313+
* }}}
314+
*
315+
* The method as implemented here does not call `size` directly; its running time
316+
* is `O(this.size min that.size)` instead of `O(this.size + that.size)`.
317+
* The method should be overridden if computing `size` is cheap and `knownSize` returns `-1`.
318+
*/
320319
def sizeCompare(that: Iterable[_]): Int = {
321320
val thatKnownSize = that.knownSize
322321

@@ -345,39 +344,39 @@ trait IterableOps[+A, +CC[_], +C] extends Any with IterableOnce[A] with Iterable
345344
def view(from: Int, until: Int): View[A] = view.slice(from, until)
346345

347346
/** Transposes this $coll of iterable collections into
348-
* a $coll of ${coll}s.
349-
*
350-
* The resulting collection's type will be guided by the
351-
* static type of $coll. For example:
352-
*
353-
* {{{
354-
* val xs = List(
355-
* Set(1, 2, 3),
356-
* Set(4, 5, 6)).transpose
357-
* // xs == List(
358-
* // List(1, 4),
359-
* // List(2, 5),
360-
* // List(3, 6))
361-
*
362-
* val ys = Vector(
363-
* List(1, 2, 3),
364-
* List(4, 5, 6)).transpose
365-
* // ys == Vector(
366-
* // Vector(1, 4),
367-
* // Vector(2, 5),
368-
* // Vector(3, 6))
369-
* }}}
370-
*
371-
* $willForceEvaluation
372-
*
373-
* @tparam B the type of the elements of each iterable collection.
374-
* @param asIterable an implicit conversion which asserts that the
375-
* element type of this $coll is an `Iterable`.
376-
* @return a two-dimensional $coll of ${coll}s which has as ''n''th row
377-
* the ''n''th column of this $coll.
378-
* @throws IllegalArgumentException if all collections in this $coll
379-
* are not of the same size.
380-
*/
347+
* a $coll of ${coll}s.
348+
*
349+
* The resulting collection's type will be guided by the
350+
* static type of $coll. For example:
351+
*
352+
* {{{
353+
* val xs = List(
354+
* Set(1, 2, 3),
355+
* Set(4, 5, 6)).transpose
356+
* // xs == List(
357+
* // List(1, 4),
358+
* // List(2, 5),
359+
* // List(3, 6))
360+
*
361+
* val ys = Vector(
362+
* List(1, 2, 3),
363+
* List(4, 5, 6)).transpose
364+
* // ys == Vector(
365+
* // Vector(1, 4),
366+
* // Vector(2, 5),
367+
* // Vector(3, 6))
368+
* }}}
369+
*
370+
* $willForceEvaluation
371+
*
372+
* @tparam B the type of the elements of each iterable collection.
373+
* @param asIterable an implicit conversion which asserts that the
374+
* element type of this $coll is an `Iterable`.
375+
* @return a two-dimensional $coll of ${coll}s which has as ''n''th row
376+
* the ''n''th column of this $coll.
377+
* @throws IllegalArgumentException if all collections in this $coll
378+
* are not of the same size.
379+
*/
381380
def transpose[B](implicit asIterable: A => /*<:<!!!*/ Iterable[B]): CC[CC[B] @uncheckedVariance] = {
382381
if (isEmpty)
383382
return iterableFactory.empty[CC[B]]
@@ -718,31 +717,31 @@ trait IterableOps[+A, +CC[_], +C] extends Any with IterableOnce[A] with Iterable
718717
}
719718

720719
/** Returns a new $ccoll containing the elements from the left hand operand followed by the elements from the
721-
* right hand operand. The element type of the $ccoll is the most specific superclass encompassing
722-
* the element types of the two operands.
723-
*
724-
* @param suffix the iterable to append.
725-
* @tparam B the element type of the returned collection.
726-
* @return a new $coll which contains all elements
727-
* of this $coll followed by all elements of `suffix`.
728-
*/
720+
* right hand operand. The element type of the $ccoll is the most specific superclass encompassing
721+
* the element types of the two operands.
722+
*
723+
* @param suffix the iterable to append.
724+
* @tparam B the element type of the returned collection.
725+
* @return a new $coll which contains all elements
726+
* of this $coll followed by all elements of `suffix`.
727+
*/
729728
def concat[B >: A](suffix: IterableOnce[B]): CC[B] = iterableFactory.from(suffix match {
730729
case xs: Iterable[B] => new View.Concat(this, xs)
731730
case xs => iterator ++ suffix.iterator
732731
})
733732

734733
/** Alias for `concat` */
735-
@`inline` final def ++ [B >: A](suffix: IterableOnce[B]): CC[B] = concat(suffix)
734+
@inline final def ++ [B >: A](suffix: IterableOnce[B]): CC[B] = concat(suffix)
736735

737-
/** Returns a $coll formed from this $coll and another iterable collection
738-
* by combining corresponding elements in pairs.
739-
* If one of the two collections is longer than the other, its remaining elements are ignored.
740-
*
741-
* @param that The iterable providing the second half of each result pair
742-
* @tparam B the type of the second half of the returned pairs
743-
* @return a new $coll containing pairs consisting of corresponding elements of this $coll and `that`.
744-
* The length of the returned collection is the minimum of the lengths of this $coll and `that`.
745-
*/
736+
/** Returns a $ccoll formed from this $coll and another iterable collection
737+
* by combining corresponding elements in pairs.
738+
* If one of the two collections is longer than the other, its remaining elements are ignored.
739+
*
740+
* @param that The iterable providing the second half of each result pair
741+
* @tparam B the type of the second half of the returned pairs
742+
* @return a new $ccoll containing pairs consisting of corresponding elements of this $coll and `that`.
743+
* The length of the returned collection is the minimum of the lengths of this $coll and `that`.
744+
*/
746745
def zip[B](that: IterableOnce[B]): CC[(A @uncheckedVariance, B)] = iterableFactory.from(that match { // sound bcs of VarianceNote
747746
case that: Iterable[B] => new View.Zip(this, that)
748747
case _ => iterator.zip(that)

library/src/scala/collection/IterableOnce.scala

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -453,36 +453,35 @@ trait IterableOnceOps[+A, +CC[_], +C] extends Any { this: IterableOnce[A] =>
453453
* For example:
454454
*
455455
* {{{
456-
* def getWords(lines: Seq[String]): Seq[String] = lines flatMap (line => line split "\\W+")
456+
* def getWords(lines: Seq[String]): Seq[String] = lines.flatMap(line => line.split("\\W+"))
457457
* }}}
458458
*
459-
* The type of the resulting collection is guided by the static type of $coll. This might
459+
* The type of the resulting collection is guided by the static type of this $coll. This might
460460
* cause unexpected results sometimes. For example:
461461
*
462462
* {{{
463463
* // lettersOf will return a Seq[Char] of likely repeated letters, instead of a Set
464-
* def lettersOf(words: Seq[String]) = words flatMap (word => word.toSet)
464+
* def lettersOf(words: Seq[String]) = words.flatMap(word => word.toSet)
465465
*
466466
* // lettersOf will return a Set[Char], not a Seq
467-
* def lettersOf(words: Seq[String]) = words.toSet flatMap ((word: String) => word.toSeq)
467+
* def lettersOf(words: Seq[String]) = words.toSet.flatMap(word => word.toSeq)
468468
*
469469
* // xs will be an Iterable[Int]
470-
* val xs = Map("a" -> List(11,111), "b" -> List(22,222)).flatMap(_._2)
470+
* val xs = Map("a" -> List(11, 111), "b" -> List(22, 222)).flatMap(_._2)
471471
*
472472
* // ys will be a Map[Int, Int]
473-
* val ys = Map("a" -> List(1 -> 11,1 -> 111), "b" -> List(2 -> 22,2 -> 222)).flatMap(_._2)
473+
* val ys = Map("a" -> List(1 -> 11, 1 -> 111), "b" -> List(2 -> 22, 2 -> 222)).flatMap(_._2)
474474
* }}}
475475
*
476476
* @param f the function to apply to each element.
477477
* @tparam B the element type of the returned collection.
478-
* @return a new $coll resulting from applying the given collection-valued function
478+
* @return a new $ccoll resulting from applying the given collection-valued function
479479
* `f` to each element of this $coll and concatenating the results.
480480
*/
481481
def flatMap[B](f: A => IterableOnce[B]): CC[B]
482482

483-
/** Converts this $coll of iterable collections into
484-
* a $coll formed by the elements of these iterable
485-
* collections.
483+
/** Given that the elements of this collection are themselves iterable collections,
484+
* converts this $coll into a $ccoll comprising the elements of these iterable collections.
486485
*
487486
* The resulting collection's type will be guided by the
488487
* type of $coll. For example:
@@ -504,24 +503,24 @@ trait IterableOnceOps[+A, +CC[_], +C] extends Any { this: IterableOnce[A] =>
504503
* @tparam B the type of the elements of each iterable collection.
505504
* @param asIterable an implicit conversion which asserts that the element
506505
* type of this $coll is an `Iterable`.
507-
* @return a new $coll resulting from concatenating all element ${coll}s.
506+
* @return a new $ccoll resulting from concatenating all element collections.
508507
*/
509508
def flatten[B](implicit asIterable: A => IterableOnce[B]): CC[B]
510509

511-
/** Builds a new $coll by applying a partial function to all elements of this $coll
510+
/** Builds a new $ccoll by applying a partial function to all elements of this $coll
512511
* on which the function is defined.
513512
*
514513
* @param pf the partial function which filters and maps the $coll.
515514
* @tparam B the element type of the returned $coll.
516-
* @return a new $coll resulting from applying the given partial function
515+
* @return a new $ccoll resulting from applying the given partial function
517516
* `pf` to each element on which it is defined and collecting the results.
518517
* The order of the elements is preserved.
519518
*/
520519
def collect[B](pf: PartialFunction[A, B]): CC[B]
521520

522521
/** Zips this $coll with its indices.
523522
*
524-
* @return A new $coll containing pairs consisting of all elements of this $coll paired with their index.
523+
* @return A new $ccoll containing pairs consisting of all elements of this $coll paired with their index.
525524
* Indices start at `0`.
526525
* @example
527526
* `List("a", "b", "c").zipWithIndex == List(("a", 0), ("b", 1), ("c", 2))`
@@ -532,7 +531,7 @@ trait IterableOnceOps[+A, +CC[_], +C] extends Any { this: IterableOnce[A] =>
532531
*
533532
* Note: `c span p` is equivalent to (but possibly more efficient than)
534533
* `(c takeWhile p, c dropWhile p)`, provided the evaluation of the
535-
* predicate `p` does not cause any side-effects.
534+
* predicate `p` does not cause any side effects.
536535
* $orderDependent
537536
*
538537
* @param p the test predicate

library/src/scala/collection/Seq.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,11 @@ trait SeqOps[+A, +CC[_], +C] extends Any
180180
def appendedAll[B >: A](suffix: IterableOnce[B]): CC[B] = super.concat(suffix)
181181

182182
/** Alias for `appendedAll`. */
183-
@`inline` final def :++ [B >: A](suffix: IterableOnce[B]): CC[B] = appendedAll(suffix)
183+
@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
186186
// overrides of this method
187-
@`inline` final override def concat[B >: A](suffix: IterableOnce[B]): CC[B] = appendedAll(suffix)
187+
@inline final override def concat[B >: A](suffix: IterableOnce[B]): CC[B] = appendedAll(suffix)
188188

189189
/** Produces a new sequence which contains all elements of this $coll and also all elements of
190190
* a given sequence. `xs union ys` is equivalent to `xs ++ ys`.
@@ -286,7 +286,7 @@ trait SeqOps[+A, +CC[_], +C] extends Any
286286
* @param len the target length
287287
* @param elem the padding value
288288
* @tparam B the element type of the returned $coll.
289-
* @return a new $coll consisting of
289+
* @return a new $ccoll consisting of
290290
* all elements of this $coll followed by the minimal number of occurrences of `elem` so
291291
* that the resulting collection has a length of at least `len`.
292292
*/

0 commit comments

Comments
 (0)