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