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