@@ -19,242 +19,242 @@ object opaques:
19
19
* @param n the index of the element to select
20
20
* @return the element of the array at the given index
21
21
*/
22
- def (arr : IArray [Byte ]) apply(n : Int ): Byte = arr.asInstanceOf [Array [Byte ]].apply(n)
23
- def (arr : IArray [Short ]) apply(n : Int ): Short = arr.asInstanceOf [Array [Short ]].apply(n)
24
- def (arr : IArray [Char ]) apply(n : Int ): Char = arr.asInstanceOf [Array [Char ]].apply(n)
25
- def (arr : IArray [Int ]) apply(n : Int ): Int = arr.asInstanceOf [Array [Int ]].apply(n)
26
- def (arr : IArray [Long ]) apply(n : Int ): Long = arr.asInstanceOf [Array [Long ]].apply(n)
27
- def (arr : IArray [Float ]) apply(n : Int ): Float = arr.asInstanceOf [Array [Float ]].apply(n)
28
- def (arr : IArray [Double ]) apply(n : Int ): Double = arr.asInstanceOf [Array [Double ]].apply(n)
29
- def [T <: Object ](arr : IArray [T ]) apply (n : Int ): T = arr.asInstanceOf [Array [T ]].apply(n)
30
- def [T ](arr : IArray [T ]) apply (n : Int ): T = arr.asInstanceOf [Array [T ]].apply(n)
22
+ extension (arr : IArray [Byte ]) def apply (n : Int ): Byte = arr.asInstanceOf [Array [Byte ]].apply(n)
23
+ extension (arr : IArray [Short ]) def apply (n : Int ): Short = arr.asInstanceOf [Array [Short ]].apply(n)
24
+ extension (arr : IArray [Char ]) def apply (n : Int ): Char = arr.asInstanceOf [Array [Char ]].apply(n)
25
+ extension (arr : IArray [Int ]) def apply (n : Int ): Int = arr.asInstanceOf [Array [Int ]].apply(n)
26
+ extension (arr : IArray [Long ]) def apply (n : Int ): Long = arr.asInstanceOf [Array [Long ]].apply(n)
27
+ extension (arr : IArray [Float ]) def apply (n : Int ): Float = arr.asInstanceOf [Array [Float ]].apply(n)
28
+ extension (arr : IArray [Double ]) def apply (n : Int ): Double = arr.asInstanceOf [Array [Double ]].apply(n)
29
+ extension [T <: Object ](arr : IArray [T ]) def apply (n : Int ): T = arr.asInstanceOf [Array [T ]].apply(n)
30
+ extension [T ](arr : IArray [T ]) def apply (n : Int ): T = arr.asInstanceOf [Array [T ]].apply(n)
31
31
32
32
/** The number of elements in an immutable array
33
33
* @param arr the immutable array
34
34
*/
35
- def (arr : IArray [Byte ]) length : Int = arr.asInstanceOf [Array [Byte ]].length
36
- def (arr : IArray [Short ]) length : Int = arr.asInstanceOf [Array [Short ]].length
37
- def (arr : IArray [Char ]) length : Int = arr.asInstanceOf [Array [Char ]].length
38
- def (arr : IArray [Int ]) length : Int = arr.asInstanceOf [Array [Int ]].length
39
- def (arr : IArray [Long ]) length : Int = arr.asInstanceOf [Array [Long ]].length
40
- def (arr : IArray [Float ]) length : Int = arr.asInstanceOf [Array [Float ]].length
41
- def (arr : IArray [Double ]) length : Int = arr.asInstanceOf [Array [Double ]].length
42
- def (arr : IArray [Object ]) length : Int = arr.asInstanceOf [Array [Object ]].length
43
- def [T ](arr : IArray [T ]) length : Int = arr.asInstanceOf [Array [T ]].length
35
+ extension (arr : IArray [Byte ]) def length : Int = arr.asInstanceOf [Array [Byte ]].length
36
+ extension (arr : IArray [Short ]) def length : Int = arr.asInstanceOf [Array [Short ]].length
37
+ extension (arr : IArray [Char ]) def length : Int = arr.asInstanceOf [Array [Char ]].length
38
+ extension (arr : IArray [Int ]) def length : Int = arr.asInstanceOf [Array [Int ]].length
39
+ extension (arr : IArray [Long ]) def length : Int = arr.asInstanceOf [Array [Long ]].length
40
+ extension (arr : IArray [Float ]) def length : Int = arr.asInstanceOf [Array [Float ]].length
41
+ extension (arr : IArray [Double ]) def length : Int = arr.asInstanceOf [Array [Double ]].length
42
+ extension (arr : IArray [Object ]) def length : Int = arr.asInstanceOf [Array [Object ]].length
43
+ extension [T ](arr : IArray [T ]) def length : Int = arr.asInstanceOf [Array [T ]].length
44
44
45
45
/** Returns this array concatenated with the given array. */
46
- def [T , U >: T : ClassTag ](arr : IArray [T ]) ++ (that : IArray [U ]): IArray [U ] =
46
+ extension [T , U >: T : ClassTag ](arr : IArray [T ]) def ++ (that : IArray [U ]): IArray [U ] =
47
47
genericArrayOps(arr) ++ that
48
48
49
49
/** Tests whether this array contains a given value as an element. */
50
- def [T ](arr : IArray [T ]) contains(elem : T ): Boolean =
50
+ extension [T ](arr : IArray [T ]) def contains (elem : T ): Boolean =
51
51
// `genericArrayOps(arr).contains(elem)` does not work because `elem` does not have type `arr.T`
52
52
// but we can use `exists` instead, which is how `ArrayOps#contains` itself is implemented:
53
53
genericArrayOps(arr).exists(_ == elem)
54
54
55
55
/** Counts the number of elements in this array which satisfy a predicate */
56
- def [T ](arr : IArray [T ]) count(p : T => Boolean ): Int =
56
+ extension [T ](arr : IArray [T ]) def count (p : T => Boolean ): Int =
57
57
genericArrayOps(arr).count(p)
58
58
59
59
/** The rest of the array without its `n` first elements. */
60
- def [T ](arr : IArray [T ]) drop(n : Int ): IArray [T ] =
60
+ extension [T ](arr : IArray [T ]) def drop (n : Int ): IArray [T ] =
61
61
genericArrayOps(arr).drop(n)
62
62
63
63
/** The rest of the array without its `n` last elements. */
64
- def [T ](arr : IArray [T ]) dropRight(n : Int ): IArray [T ] =
64
+ extension [T ](arr : IArray [T ]) def dropRight (n : Int ): IArray [T ] =
65
65
genericArrayOps(arr).dropRight(n)
66
66
67
67
/** Drops longest prefix of elements that satisfy a predicate. */
68
- def [T ](arr : IArray [T ]) dropWhile(p : T => Boolean ): IArray [T ] =
68
+ extension [T ](arr : IArray [T ]) def dropWhile (p : T => Boolean ): IArray [T ] =
69
69
genericArrayOps(arr).dropWhile(p)
70
70
71
71
/** Tests whether a predicate holds for at least one element of this array. */
72
- def [T ](arr : IArray [T ]) exists(p : T => Boolean ): Boolean =
72
+ extension [T ](arr : IArray [T ]) def exists (p : T => Boolean ): Boolean =
73
73
genericArrayOps(arr).exists(p)
74
74
75
75
/** Selects all elements of this array which satisfy a predicate. */
76
- def [T ](arr : IArray [T ]) filter(p : T => Boolean ): IArray [T ] =
76
+ extension [T ](arr : IArray [T ]) def filter (p : T => Boolean ): IArray [T ] =
77
77
genericArrayOps(arr).filter(p)
78
78
79
79
/** Selects all elements of this array which do not satisfy a predicate. */
80
- def [T ](arr : IArray [T ]) filterNot(p : T => Boolean ): IArray [T ] =
80
+ extension [T ](arr : IArray [T ]) def filterNot (p : T => Boolean ): IArray [T ] =
81
81
genericArrayOps(arr).filterNot(p)
82
82
83
83
/** Finds the first element of the array satisfying a predicate, if any. */
84
- def [T ](arr : IArray [T ]) find(p : T => Boolean ): Option [T ] =
84
+ extension [T ](arr : IArray [T ]) def find (p : T => Boolean ): Option [T ] =
85
85
genericArrayOps(arr).find(p)
86
86
87
87
/** Builds a new array by applying a function to all elements of this array
88
88
* and using the elements of the resulting collections. */
89
- def [T , U : ClassTag ](arr : IArray [T ]) flatMap(f : T => IterableOnce [U ]): IArray [U ] =
89
+ extension [T , U : ClassTag ](arr : IArray [T ]) def flatMap (f : T => IterableOnce [U ]): IArray [U ] =
90
90
genericArrayOps(arr).flatMap(f)
91
91
92
92
/** Flattens a two-dimensional array by concatenating all its rows
93
93
* into a single array. */
94
- def [T , U : ClassTag ](arr : IArray [T ]) flatten(using T => Iterable [U ]): IArray [U ] =
94
+ extension [T , U : ClassTag ](arr : IArray [T ]) def flatten (using T => Iterable [U ]): IArray [U ] =
95
95
genericArrayOps(arr).flatten
96
96
97
97
/** Folds the elements of this array using the specified associative binary operator. */
98
- def [T , U >: T : ClassTag ](arr : IArray [T ]) fold(z : U )(op : (U , U ) => U ): U =
98
+ extension [T , U >: T : ClassTag ](arr : IArray [T ]) def fold (z : U )(op : (U , U ) => U ): U =
99
99
genericArrayOps(arr).fold(z)(op)
100
100
101
101
/** Applies a binary operator to a start value and all elements of this array,
102
102
* going left to right. */
103
- def [T , U : ClassTag ](arr : IArray [T ]) foldLeft(z : U )(op : (U , T ) => U ): U =
103
+ extension [T , U : ClassTag ](arr : IArray [T ]) def foldLeft (z : U )(op : (U , T ) => U ): U =
104
104
genericArrayOps(arr).foldLeft(z)(op)
105
105
106
106
/** Applies a binary operator to all elements of this array and a start value,
107
107
* going right to left. */
108
- def [T , U : ClassTag ](arr : IArray [T ]) foldRight(z : U )(op : (T , U ) => U ): U =
108
+ extension [T , U : ClassTag ](arr : IArray [T ]) def foldRight (z : U )(op : (T , U ) => U ): U =
109
109
genericArrayOps(arr).foldRight(z)(op)
110
110
111
111
/** Tests whether a predicate holds for all elements of this array. */
112
- def [T ](arr : IArray [T ]) forall(p : T => Boolean ): Boolean =
112
+ extension [T ](arr : IArray [T ]) def forall (p : T => Boolean ): Boolean =
113
113
genericArrayOps(arr).forall(p)
114
114
115
115
/** Apply `f` to each element for its side effects. */
116
- def [T , U ](arr : IArray [T ]) foreach(f : T => U ): Unit =
116
+ extension [T , U ](arr : IArray [T ]) def foreach (f : T => U ): Unit =
117
117
genericArrayOps(arr).foreach(f)
118
118
119
119
/** Selects the first element of this array. */
120
- def [T ](arr : IArray [T ]) head : T =
120
+ extension [T ](arr : IArray [T ]) def head : T =
121
121
genericArrayOps(arr).head
122
122
123
123
/** Optionally selects the first element. */
124
- def [T ](arr : IArray [T ]) headOption : Option [T ] =
124
+ extension [T ](arr : IArray [T ]) def headOption : Option [T ] =
125
125
genericArrayOps(arr).headOption
126
126
127
127
/** Finds index of first occurrence of some value in this array after or at some start index. */
128
- def [T ](arr : IArray [T ]) indexOf(elem : T , from : Int = 0 ): Int =
128
+ extension [T ](arr : IArray [T ]) def indexOf (elem : T , from : Int = 0 ): Int =
129
129
// `asInstanceOf` needed because `elem` does not have type `arr.T`
130
130
// We could use `arr.iterator.indexOf(elem, from)` or `arr.indexWhere(_ == elem, from)`
131
131
// but these would incur some overhead.
132
132
genericArrayOps(arr).indexOf(elem.asInstanceOf , from)
133
133
134
134
/** Finds index of the first element satisfying some predicate after or at some start index. */
135
- def [T ](arr : IArray [T ]) indexWhere(p : T => Boolean , from : Int = 0 ): Int =
135
+ extension [T ](arr : IArray [T ]) def indexWhere (p : T => Boolean , from : Int = 0 ): Int =
136
136
genericArrayOps(arr).indexWhere(p, from)
137
137
138
138
/** Produces the range of all indices of this sequence. */
139
- def [T ](arr : IArray [T ]) indices : Range =
139
+ extension [T ](arr : IArray [T ]) def indices : Range =
140
140
genericArrayOps(arr).indices
141
141
142
142
/** The initial part of the array without its last element. */
143
- def [T ](arr : IArray [T ]) init : IArray [T ] =
143
+ extension [T ](arr : IArray [T ]) def init : IArray [T ] =
144
144
genericArrayOps(arr).init
145
145
146
146
/** Tests whether the array is empty. */
147
- def [T ](arr : IArray [T ]) isEmpty : Boolean =
147
+ extension [T ](arr : IArray [T ]) def isEmpty : Boolean =
148
148
genericArrayOps(arr).isEmpty
149
149
150
150
/** An iterator yielding the elemenst of this array. */
151
- def [T ](arr : IArray [T ]) iterator : Iterator [T ] =
151
+ extension [T ](arr : IArray [T ]) def iterator : Iterator [T ] =
152
152
genericArrayOps(arr).iterator
153
153
154
154
/** Selects the last element. */
155
- def [T ](arr : IArray [T ]) last : T =
155
+ extension [T ](arr : IArray [T ]) def last : T =
156
156
genericArrayOps(arr).last
157
157
158
158
/** Optionally selects the last element. */
159
- def [T ](arr : IArray [T ]) lastOption : Option [T ] =
159
+ extension [T ](arr : IArray [T ]) def lastOption : Option [T ] =
160
160
genericArrayOps(arr).lastOption
161
161
162
162
/** Finds index of last occurrence of some value in this array before or at a given end index. */
163
- def [T ](arr : IArray [T ]) lastIndexOf(elem : T , end : Int = arr.length - 1 ): Int =
163
+ extension [T ](arr : IArray [T ]) def lastIndexOf (elem : T , end : Int = arr.length - 1 ): Int =
164
164
// see: same issue in `indexOf`
165
165
genericArrayOps(arr).lastIndexOf(elem.asInstanceOf , end)
166
166
167
167
/** Finds index of last element satisfying some predicate before or at given end index. */
168
- def [T ](arr : IArray [T ]) lastIndexWhere(p : T => Boolean , end : Int = arr.length - 1 ): Int =
168
+ extension [T ](arr : IArray [T ]) def lastIndexWhere (p : T => Boolean , end : Int = arr.length - 1 ): Int =
169
169
genericArrayOps(arr).lastIndexWhere(p, end)
170
170
171
171
/** Builds a new array by applying a function to all elements of this array. */
172
- def [T , U : ClassTag ](arr : IArray [T ]) map(f : T => U ): IArray [U ] =
172
+ extension [T , U : ClassTag ](arr : IArray [T ]) def map (f : T => U ): IArray [U ] =
173
173
genericArrayOps(arr).map(f)
174
174
175
175
/** Tests whether the array is not empty. */
176
- def [T ](arr : IArray [T ]) nonEmpty : Boolean =
176
+ extension [T ](arr : IArray [T ]) def nonEmpty : Boolean =
177
177
genericArrayOps(arr).nonEmpty
178
178
179
179
/** A pair of, first, all elements that satisfy predicate `p` and, second, all elements that do not. */
180
- def [T ](arr : IArray [T ]) partition(p : T => Boolean ): (IArray [T ], IArray [T ]) =
180
+ extension [T ](arr : IArray [T ]) def partition (p : T => Boolean ): (IArray [T ], IArray [T ]) =
181
181
genericArrayOps(arr).partition(p)
182
182
183
183
/** Returns a new array with the elements in reversed order. */
184
- def [T ](arr : IArray [T ]) reverse : IArray [T ] =
184
+ extension [T ](arr : IArray [T ]) def reverse : IArray [T ] =
185
185
genericArrayOps(arr).reverse
186
186
187
187
/** Computes a prefix scan of the elements of the array. */
188
- def [T , U >: T : ClassTag ](arr : IArray [T ]) scan(z : U )(op : (U , U ) => U ): IArray [U ] =
188
+ extension [T , U >: T : ClassTag ](arr : IArray [T ]) def scan (z : U )(op : (U , U ) => U ): IArray [U ] =
189
189
genericArrayOps(arr).scan(z)(op)
190
190
191
191
/** Produces an array containing cumulative results of applying the binary
192
192
* operator going left to right. */
193
- def [T , U : ClassTag ](arr : IArray [T ]) scanLeft(z : U )(op : (U , T ) => U ): IArray [U ] =
193
+ extension [T , U : ClassTag ](arr : IArray [T ]) def scanLeft (z : U )(op : (U , T ) => U ): IArray [U ] =
194
194
genericArrayOps(arr).scanLeft(z)(op)
195
195
196
196
/** Produces an array containing cumulative results of applying the binary
197
197
* operator going right to left. */
198
- def [T , U : ClassTag ](arr : IArray [T ]) scanRight(z : U )(op : (T , U ) => U ): IArray [U ] =
198
+ extension [T , U : ClassTag ](arr : IArray [T ]) def scanRight (z : U )(op : (T , U ) => U ): IArray [U ] =
199
199
genericArrayOps(arr).scanRight(z)(op)
200
200
201
201
/** The size of this array. */
202
- def [T ](arr : IArray [T ]) size : Int =
202
+ extension [T ](arr : IArray [T ]) def size : Int =
203
203
arr.length
204
204
205
205
/** Selects the interval of elements between the given indices. */
206
- def [T ](arr : IArray [T ]) slice(from : Int , until : Int ): IArray [T ] =
206
+ extension [T ](arr : IArray [T ]) def slice (from : Int , until : Int ): IArray [T ] =
207
207
genericArrayOps(arr).slice(from, until)
208
208
209
209
/** Sorts this array according to the Ordering which results from transforming
210
210
* an implicitly given Ordering with a transformation function. */
211
- def [T , U : ClassTag ](arr : IArray [T ]) sortBy(f : T => U )(using math.Ordering [U ]): IArray [T ] =
211
+ extension [T , U : ClassTag ](arr : IArray [T ]) def sortBy (f : T => U )(using math.Ordering [U ]): IArray [T ] =
212
212
genericArrayOps(arr).sortBy(f)
213
213
214
214
/** Sorts this array according to a comparison function. */
215
- def [T ](arr : IArray [T ]) sortWith(f : (T , T ) => Boolean ): IArray [T ] =
215
+ extension [T ](arr : IArray [T ]) def sortWith (f : (T , T ) => Boolean ): IArray [T ] =
216
216
genericArrayOps(arr).sortWith(f)
217
217
218
218
/** Sorts this array according to an Ordering. */
219
- def [T ](arr : IArray [T ]) sorted(using math.Ordering [T ]): IArray [T ] =
219
+ extension [T ](arr : IArray [T ]) def sorted (using math.Ordering [T ]): IArray [T ] =
220
220
genericArrayOps(arr).sorted
221
221
222
222
/** Splits this array into a prefix/suffix pair according to a predicate. */
223
- def [T ](arr : IArray [T ]) span(p : T => Boolean ): (IArray [T ], IArray [T ]) =
223
+ extension [T ](arr : IArray [T ]) def span (p : T => Boolean ): (IArray [T ], IArray [T ]) =
224
224
genericArrayOps(arr).span(p)
225
225
226
226
/** Splits this array into two at a given position. */
227
- def [T ](arr : IArray [T ]) splitAt(n : Int ): (IArray [T ], IArray [T ]) =
227
+ extension [T ](arr : IArray [T ]) def splitAt (n : Int ): (IArray [T ], IArray [T ]) =
228
228
genericArrayOps(arr).splitAt(n)
229
229
230
230
/** Tests whether this array starts with the given array. */
231
- def [T , U >: T : ClassTag ](arr : IArray [T ]) startsWith(that : IArray [U ], offset : Int = 0 ): Boolean =
231
+ extension [T , U >: T : ClassTag ](arr : IArray [T ]) def startsWith (that : IArray [U ], offset : Int = 0 ): Boolean =
232
232
genericArrayOps(arr).startsWith(that)
233
233
234
234
/** The rest of the array without its first element. */
235
- def [T ](arr : IArray [T ]) tail : IArray [T ] =
235
+ extension [T ](arr : IArray [T ]) def tail : IArray [T ] =
236
236
genericArrayOps(arr).tail
237
237
238
238
/** An array containing the first `n` elements of this array. */
239
- def [T ](arr : IArray [T ]) take(n : Int ): IArray [T ] =
239
+ extension [T ](arr : IArray [T ]) def take (n : Int ): IArray [T ] =
240
240
genericArrayOps(arr).take(n)
241
241
242
242
/** An array containing the last `n` elements of this array. */
243
- def [T ](arr : IArray [T ]) takeRight(n : Int ): IArray [T ] =
243
+ extension [T ](arr : IArray [T ]) def takeRight (n : Int ): IArray [T ] =
244
244
genericArrayOps(arr).takeRight(n)
245
245
246
246
/** Takes longest prefix of elements that satisfy a predicate. */
247
- def [T ](arr : IArray [T ]) takeWhile(p : T => Boolean ): IArray [T ] =
247
+ extension [T ](arr : IArray [T ]) def takeWhile (p : T => Boolean ): IArray [T ] =
248
248
genericArrayOps(arr).takeWhile(p)
249
249
250
250
/** Converts an array of pairs into an array of first elements and an array of second elements. */
251
- def [U : ClassTag , V : ClassTag ](arr : IArray [(U , V )]) unzip : (IArray [U ], IArray [V ]) =
251
+ extension [U : ClassTag , V : ClassTag ](arr : IArray [(U , V )]) def unzip : (IArray [U ], IArray [V ]) =
252
252
genericArrayOps(arr).unzip
253
253
254
254
/** Returns an array formed from this array and another iterable collection
255
255
* by combining corresponding elements in pairs.
256
256
* If one of the two collections is longer than the other, its remaining elements are ignored. */
257
- def [T , U : ClassTag ](arr : IArray [T ]) zip(that : IArray [U ]): IArray [(T , U )] =
257
+ extension [T , U : ClassTag ](arr : IArray [T ]) def zip (that : IArray [U ]): IArray [(T , U )] =
258
258
genericArrayOps(arr).zip(that)
259
259
}
260
260
end opaques
0 commit comments