1
+ package scala .collection
2
+ package immutable
3
+
4
+ import scala .collection .Stepper .EfficientSplit
5
+ import scala .collection .immutable .Range
6
+ import scala .collection .mutable .Buffer
7
+ import scala .collection .IterableOps .SizeCompareOps
8
+ import scala .collection .Searching .SearchResult
9
+ import scala .math .Ordering
10
+ import scala .reflect .ClassTag
11
+ import scala .util .Sorting
12
+ import annotation .targetName
13
+
14
+ opaque type Repeated [+ A ] = Seq [A ]
15
+ object Repeated :
16
+
17
+ extension [A ](xs : Repeated [A ])
18
+ def length : Int = xs.length
19
+ def apply (n : Int ) = xs.apply(n)
20
+ def iterator : Iterator [A ] = xs.iterator
21
+
22
+ def ++ [B >: A ](suffix : IterableOnce [B ]): Repeated [B ] = xs ++ suffix
23
+ def :+ [B >: A ](x : B ): Repeated [B ] = xs :+ x
24
+ def :++ [B >: A ](suffix : IterableOnce [B ]): Repeated [B ] = xs :++ suffix
25
+
26
+ def addString (b : mutable.StringBuilder ): mutable.StringBuilder = xs.addString(b)
27
+ def addString (b : mutable.StringBuilder , sep : String ): mutable.StringBuilder = xs.addString(b, sep)
28
+ def addString (b : mutable.StringBuilder , start : String , sep : String , end : String ): mutable.StringBuilder = xs.addString(b, start, sep, end)
29
+ def appended [B >: A ](x : B ): Repeated [B ] = xs.appended(x)
30
+ def appendedAll [B >: A ](suffix : IterableOnce [B ]): Repeated [B ] = xs.appendedAll(suffix)
31
+ def collect [B ](pf : PartialFunction [A , B ]): Repeated [B ] = xs.collect(pf)
32
+ def collectFirst [B ](f : PartialFunction [A , B ]): Option [B ] = xs.collectFirst(f)
33
+ def combinations (n : Int ): Iterator [Repeated [A ]] = xs.combinations(n)
34
+ def concat [B >: A ](suffix : IterableOnce [B ]): Repeated [B ] = xs.concat(suffix)
35
+ def contains (elem : A ): Boolean = xs.contains(elem)
36
+ def containsSlice [B ](that : Seq [B ]): Boolean = xs.containsSlice(that)
37
+ def copyToArray [B >: A ](ys : Array [B ]): Int = xs.copyToArray(ys)
38
+ def copyToArray [B >: A ](ys : Array [B ], start : Int ): Int = xs.copyToArray(ys, start)
39
+ def copyToArray [B >: A ](ys : Array [B ], start : Int , len : Int ): Int = xs.copyToArray(ys, start, len)
40
+ def corresponds [B ](that : IterableOnce [B ])(p : (A , B ) => Boolean ): Boolean = xs.corresponds(that)(p)
41
+ def count (p : A => Boolean ): Int = xs.count(p)
42
+ def diff [B >: A ](that : Seq [B ]): Repeated [A ] = xs.diff(that)
43
+ def distinct : Repeated [A ] = xs.distinct
44
+ def distinctBy [B ](f : A => B ): Repeated [A ] = xs.distinctBy(f)
45
+ def drop (n : Int ): Repeated [A ] = xs.drop(n)
46
+ def dropRight (n : Int ): Repeated [A ] = xs.dropRight(n)
47
+ def dropWhile (p : A => Boolean ): Repeated [A ] = xs.dropWhile(p)
48
+ def empty : Repeated [A ] = xs.empty
49
+ def endsWith [B >: A ](that : Iterable [B ]): Boolean = xs.endsWith(that)
50
+ def exists (p : A => Boolean ): Boolean = xs.exists(p)
51
+ def filter (p : A => Boolean ): Repeated [A ] = xs.filter(p)
52
+ def filterNot (p : A => Boolean ): Repeated [A ] = xs.filterNot(p)
53
+ def find (p : A => Boolean ): Option [A ] = xs.find(p)
54
+ def findLast (p : A => Boolean ): Option [A ] = xs.findLast(p)
55
+ def flatMap [B ](f : A => IterableOnce [B ]): Repeated [B ] = xs.flatMap(f)
56
+ def fold [A1 >: A ](z : A1 )(op : (A1 , A1 ) => A1 ): A1 = xs.fold(z)(op)
57
+ def foldLeft [B ](z : B )(op : (B , A ) => B ): B = xs.foldLeft(z)(op)
58
+ def foldRight [B ](z : B )(op : (A , B ) => B ): B = xs.foldRight(z)(op)
59
+ def forall (p : A => Boolean ): Boolean = xs.forall(p)
60
+ def foreach [U ](f : A => U ): Unit = xs.foreach(f)
61
+ def groupBy [K ](f : A => K ): immutable.Map [K , Repeated [A ]] = xs.groupBy(f)
62
+ def groupMap [K , B ](key : A => K )(f : A => B ): immutable.Map [K , Repeated [B ]] = xs.groupMap(key)(f)
63
+ def groupMapReduce [K , B ](key : (A ) => K )(f : (A ) => B )(reduce : (B , B ) => B ): immutable.Map [K , B ] = xs.groupMapReduce(key)(f)(reduce)
64
+ def grouped (size : Int ): Iterator [Repeated [A ]] = xs.grouped(size)
65
+ def head : A = xs.head
66
+ def headOption : Option [A ] = xs.headOption
67
+ def indexOf (elem : A , from : Int = 0 ): Int = xs.indexOf(elem, from)
68
+ def indexOfSlice [B >: A ](that : Seq [B ]): Int = xs.indexOfSlice(that)
69
+ def indexOfSlice [B >: A ](that : Seq [B ], from : Int ): Int = xs.indexOfSlice(that, from)
70
+ def indexWhere (p : A => Boolean , from : Int = 0 ): Int = xs.indexWhere(p, from)
71
+ def indices : Range = xs.indices
72
+ def init : Repeated [A ] = xs.init
73
+ def inits : Iterator [Repeated [A ]] = xs.inits
74
+ def intersect [B >: A ](that : Seq [B ]): Repeated [A ] = xs.intersect(that)
75
+ def isEmpty : Boolean = xs.isEmpty
76
+ def isTraversableAgain : Boolean = xs.isTraversableAgain
77
+ def knownSize : Int = xs.length
78
+ def last : A = xs.last
79
+ def lastIndexOf (elem : A , end : Int = xs.length - 1 ): Int = xs.lastIndexOf(elem, end)
80
+ def lastIndexOfSlice [B >: A ](that : Seq [B ]): Int = xs.lastIndexOfSlice(that)
81
+ def lastIndexOfSlice [B >: A ](that : Seq [B ], end : Int ): Int = xs.lastIndexOfSlice(that, end)
82
+ def lastIndexWhere (p : A => Boolean , end : Int = xs.length - 1 ): Int = xs.lastIndexWhere(p, end)
83
+ def lastOption : Option [A ] = xs.lastOption
84
+ def lazyZip [B ](that : Iterable [B ]): LazyZip2 [A , B , Repeated [A ]] = xs.lazyZip[B ](that).asInstanceOf [LazyZip2 [A , B , Repeated [A ]]]
85
+ def lengthCompare (len : Int ): Int = xs.lengthCompare(len)
86
+ def lengthIs : SizeCompareOps = xs.lengthIs
87
+ def map [B ](f : A => B ): Repeated [B ] = xs.map(f)
88
+ def max [B >: A ](using math.Ordering [B ]): A = xs.max[B ]
89
+ def maxBy [B ](f : A => B )(using math.Ordering [B ]): A = xs.maxBy(f)
90
+ def maxByOption [B ](f : A => B )(using math.Ordering [B ]): Option [A ] = xs.maxByOption(f)
91
+ def maxOption [B >: A ](using math.Ordering [B ]): Option [B ] = xs.maxOption[B ]
92
+ def min [B >: A ](using math.Ordering [B ]): A = xs.min[B ]
93
+ def minBy [B ](f : A => B )(using math.Ordering [B ]): A = xs.minBy(f)
94
+ def minByOption [B ](f : A => B )(using math.Ordering [B ]): Option [A ] = xs.minByOption(f)
95
+ def minOption [B >: A ](using math.Ordering [B ]): Option [B ] = xs.minOption[B ]
96
+ def mkString : String = xs.mkString
97
+ def mkString (sep : String ): String = xs.mkString(sep)
98
+ def mkString (start : String , sep : String , end : String ): String = xs.mkString(start, sep, end)
99
+ def nonEmpty : Boolean = xs.nonEmpty
100
+ def padTo [B >: A ](len : Int , elem : B ): Repeated [B ] = xs.padTo(len, elem)
101
+ def partition (p : A => Boolean ): (Repeated [A ], Repeated [A ]) = xs.partition(p)
102
+ def partitionMap [A1 , A2 ](f : A => Either [A1 , A2 ]): (Repeated [A1 ], Repeated [A2 ]) = xs.partitionMap(f)
103
+ def patch [B >: A ](from : Int , other : IterableOnce [B ], replaced : Int ): Repeated [B ] = xs.patch(from, other, replaced)
104
+ def permutations : Iterator [Repeated [A ]] = xs.permutations
105
+ def prepended [B >: A ](x : B ): Repeated [B ] = xs.prepended(x)
106
+ def prependedAll [B >: A ](prefix : IterableOnce [B ]): Repeated [B ] = xs.prependedAll(prefix)
107
+ def product [B >: A ](using math.Numeric [B ]): B = xs.product[B ]
108
+ def reduce [B >: A ](op : (B , B ) => B ): B = xs.reduce(op)
109
+ def reduceLeft [B >: A ](op : (B , A ) => B ): B = xs.reduceLeft(op)
110
+ def reduceRight [B >: A ](op : (A , B ) => B ): B = xs.reduceRight(op)
111
+ def reverse : Repeated [A ] = xs.reverse
112
+ def reverseIterator : Iterator [A ] = xs.reverseIterator
113
+ def sameElements [B >: A ](that : IterableOnce [B ]): Boolean = xs.sameElements(that)
114
+ def scan [B >: A ](z : B )(op : (B , B ) => B ): Repeated [B ] = xs.scan(z)(op)
115
+ def scanLeft [B ](z : B )(op : (B , A ) => B ): Repeated [B ] = xs.scanLeft(z)(op)
116
+ def scanRight [B ](z : B )(op : (A , B ) => B ): Repeated [B ] = xs.scanRight(z)(op)
117
+ def search [B >: A ](elem : B )(using Ordering [B ]): SearchResult = xs.search(elem)
118
+ def search [B >: A ](elem : B , from : Int , to : Int )(using Ordering [B ]): SearchResult = xs.search(elem, from, to)
119
+ def segmentLength (p : (A ) => Boolean , from : Int ): Int = xs.segmentLength(p, from)
120
+ def segmentLength (p : (A ) => Boolean ): Int = xs.segmentLength(p)
121
+ def size : Int = xs.size
122
+ def sizeCompare (that : Iterable [_]): Int = xs.sizeCompare(that)
123
+ def sizeCompare (otherSize : Int ): Int = xs.sizeCompare(otherSize)
124
+ def sizeIs : SizeCompareOps = xs.sizeIs
125
+ def slice (from : Int , until : Int ): Repeated [A ] = xs.slice(from, until)
126
+ def sliding (size : Int , step : Int = 1 ): Iterator [Repeated [A ]] = xs.sliding(size, step)
127
+ def sortBy [B ](f : A => B )(implicit ord : Ordering [B ]): Repeated [A ] = xs.sortBy(f)
128
+ def sortWith (lt : (A , A ) => Boolean ): Repeated [A ] = xs.sortWith(lt)
129
+ def sorted [B >: A ](implicit ord : Ordering [B ]): Repeated [A ] = xs.sorted[B ]
130
+ def span (p : A => Boolean ): (Repeated [A ], Repeated [A ]) = xs.span(p)
131
+ def splitAt (n : Int ): (Repeated [A ], Repeated [A ]) = xs.splitAt(n)
132
+ def startsWith [B >: A ](that : IterableOnce [B ], offset : Int ): Boolean = xs.startsWith(that, offset)
133
+ def stepper [S <: Stepper [_]](using StepperShape [A , S ]): S = xs.stepper[S ]
134
+ def sum [B >: A ](using math.Numeric [B ]): B = xs.sum[B ]
135
+ def tail : Repeated [A ] = xs.tail
136
+ def tails : Iterator [Repeated [A ]] = xs.tails
137
+ def take (n : Int ): Repeated [A ] = xs.take(n)
138
+ def takeRight (n : Int ): Repeated [A ] = xs.takeRight(n)
139
+ def takeWhile (p : A => Boolean ): Repeated [A ] = xs.takeWhile(p)
140
+ def tapEach [U ](f : (A ) => U ): Repeated [A ] = xs.tapEach(f)
141
+ def to [C1 ](factory : Factory [A , C1 ]): C1 = xs.to(factory)
142
+ def toArray [B >: A : ClassTag ]: Array [B ] = xs.toArray[B ]
143
+ def toBuffer [B >: A ]: Buffer [B ] = xs.toBuffer[B ]
144
+ def toIndexedSeq : immutable.IndexedSeq [A ] = xs.toIndexedSeq
145
+ def toIterable : Iterable [A ] = xs.toIterable
146
+ def toList : List [A ] = xs.toList
147
+ def toSeq : Seq [A ] = xs.toSeq
148
+ def toSet : Set [A ] = xs.toSet
149
+ def toVector : Vector [A ] = xs.toVector
150
+ def updated [B >: A ](index : Int , elem : B ): Repeated [B ] = xs.updated(index, elem)
151
+ def view : SeqView [A ] = xs.view
152
+ def withFilter (p : A => Boolean ): WithFilter [A , Repeated ] = xs.withFilter(p)
153
+ def zip [B ](that : IterableOnce [B ]): Repeated [(A , B )] = xs.zip(that)
154
+ def zipAll [A1 >: A , B ](that : Iterable [B ], thisElem : A1 , thatElem : B ): Repeated [(A1 , B )] = xs.zipAll(that, thisElem, thatElem)
155
+ def zipWithIndex : Repeated [(A , Int )] = xs.zipWithIndex
156
+
157
+ extension [A ](xs : Repeated [IterableOnce [A ]])
158
+ def flatten : Repeated [A ] = xs.flatten
159
+
160
+ extension [A ](prefix : IterableOnce [A ])
161
+ def ++: (xs : Repeated [A ]): Repeated [A ] = xs.prependedAll(prefix)
162
+
163
+ extension [A ](x : A )
164
+ def +: (xs : Repeated [A ]): Repeated [A ] = xs.prepended(x)
165
+
166
+ extension [A1 , A2 ](xs : Repeated [(A1 , A2 )])
167
+ def unzip : (Repeated [A1 ], Repeated [A2 ]) = xs.unzip
168
+ def toMap : Map [A1 , A2 ] = xs.toMap
169
+
170
+ extension [A1 , A2 , A3 ](xs : Repeated [(A1 , A2 , A3 )])
171
+ def unzip3 : (Repeated [A1 ], Repeated [A2 ], Repeated [A3 ]) = xs.unzip3
172
+
173
+ extension [A ](xs : Repeated [Repeated [A ]])
174
+ def transpose : Repeated [Repeated [A ]] = xs.transpose
175
+
176
+ implicit def repeatedToSeq [A ](xs : Repeated [A ]): Seq [A ] = xs.toSeq
0 commit comments