@@ -102,13 +102,6 @@ namespace Microsoft.FSharp.Collections
102
102
// ineffictive **
103
103
let inline avoid boolean = match boolean with true -> true | false -> false
104
104
105
- module internal Upcast =
106
- // The f# compiler outputs unnecessary unbox.any calls in upcasts. If this functionality
107
- // is fixed with the compiler then these functions can be removed.
108
- let inline seq < 'T , 'seq when 'seq :> ISeq < 'T > and 'seq : not struct > ( t : 'seq ) : ISeq < 'T > = ( # " " t : ISeq< 'T> #)
109
- let inline enumerableNonGeneric < 'enumerable when 'enumerable :> IEnumerable and 'enumerable : not struct > ( t : 'enumerable ) : IEnumerable = ( # " " t : IEnumerable #)
110
- let inline outOfBand < 'outOfBand when 'outOfBand :> IOutOfBand and 'outOfBand : not struct > ( t : 'outOfBand ) : IOutOfBand = ( # " " t : IOutOfBand #)
111
-
112
105
let inline valueComparer < 'T when 'T : equality > ()=
113
106
let c = HashIdentity.Structural< 'T>
114
107
{ new IEqualityComparer< Value< 'T>> with
@@ -119,7 +112,7 @@ namespace Microsoft.FSharp.Collections
119
112
let empty < 'T > = Microsoft.FSharp.Collections.SeqComposition.Core.EmptyEnumerable< 'T>. Instance
120
113
121
114
[<CompiledName( " Singleton" ) >]
122
- let singleton x = Upcast.seq ( new SingletonEnumerable<_>( x))
115
+ let singleton < 'T > ( x : 'T ) : ISeq < 'T > = upcast ( new SingletonEnumerable<_>( x))
123
116
124
117
/// wraps a ResizeArray in the ISeq framework. Care must be taken that the underlying ResizeArray
125
118
/// is not modified whilst it can be accessed as the ISeq, so check on version is performed.
@@ -128,24 +121,24 @@ namespace Microsoft.FSharp.Collections
128
121
/// performed in this case. If you want this funcitonality, then use the ofSeq function instead.
129
122
[<CompiledName " OfResizeArrayUnchecked" >]
130
123
let ofResizeArrayUnchecked ( source : ResizeArray < 'T >) : ISeq < 'T > =
131
- Upcast.seq ( ThinResizeArrayEnumerable< 'T> source)
124
+ upcast ( ThinResizeArrayEnumerable< 'T> source)
132
125
133
126
[<CompiledName " OfArray" >]
134
127
let ofArray ( source : array < 'T >) : ISeq < 'T > =
135
128
checkNonNull " source" source
136
- Upcast.seq ( ThinArrayEnumerable< 'T> source)
129
+ upcast ( ThinArrayEnumerable< 'T> source)
137
130
138
131
[<CompiledName " OfList" >]
139
132
let ofList ( source : list < 'T >) : ISeq < 'T > =
140
- Upcast.seq source
133
+ upcast source
141
134
142
135
[<CompiledName " OfSeq" >]
143
136
let ofSeq ( source : seq < 'T >) : ISeq < 'T > =
144
137
match source with
145
138
| :? ISeq< 'T> as seq -> seq
146
139
| :? array< 'T> as array -> ofArray array
147
140
| null -> nullArg " source"
148
- | _ -> Upcast.seq ( ThinEnumerable< 'T> source)
141
+ | _ -> upcast ( ThinEnumerable< 'T> source)
149
142
150
143
[<CompiledName " Average" >]
151
144
let inline average ( source : ISeq < 'T >) =
@@ -187,7 +180,7 @@ namespace Microsoft.FSharp.Collections
187
180
this.Result <- value
188
181
else
189
182
this.State._ 2 <- true
190
- ( Upcast.outOfBand this) .StopFurtherProcessing pipeIdx
183
+ ( this :> IOutOfBand ) .StopFurtherProcessing pipeIdx
191
184
Unchecked.defaultof<_> (* return value unused in Fold context *)
192
185
193
186
override this.OnComplete _ =
@@ -213,25 +206,25 @@ namespace Microsoft.FSharp.Collections
213
206
if this.State.MoveNext() then
214
207
this.Result <- folder this.Result value this.State.Current
215
208
else
216
- ( Upcast.outOfBand this) .StopFurtherProcessing pipeIdx
209
+ ( this :> IOutOfBand ) .StopFurtherProcessing pipeIdx
217
210
Unchecked.defaultof<_> (* return value unused in Fold context *)
218
211
219
212
override this.OnComplete _ = ()
220
213
override this.OnDispose () = this.State.Dispose () })
221
214
222
215
[<CompiledName " Unfold" >]
223
216
let unfold ( generator : 'State -> option < 'T * 'State >) ( state : 'State ) : ISeq < 'T > =
224
- Upcast.seq ( new UnfoldEnumerable< 'T, 'T, 'State>( generator, state, IdentityFactory.Instance, 1 ))
217
+ upcast ( new UnfoldEnumerable< 'T, 'T, 'State>( generator, state, IdentityFactory.Instance, 1 ))
225
218
226
219
[<CompiledName " InitializeInfinite" >]
227
220
let initInfinite < 'T > ( f : int -> 'T ) : ISeq < 'T > =
228
- Upcast.seq ( new InitEnumerableDecider< 'T>( Nullable (), f, 1 ))
221
+ upcast ( new InitEnumerableDecider< 'T>( Nullable (), f, 1 ))
229
222
230
223
[<CompiledName " Initialize" >]
231
224
let init < 'T > ( count : int ) ( f : int -> 'T ) : ISeq < 'T > =
232
225
if count < 0 then invalidArgInputMustBeNonNegative " count" count
233
226
elif count = 0 then empty else
234
- Upcast.seq ( new InitEnumerableDecider< 'T>( Nullable count, f, 1 ))
227
+ upcast ( new InitEnumerableDecider< 'T>( Nullable count, f, 1 ))
235
228
236
229
[<CompiledName " Iterate" >]
237
230
let inline iter f ( source : ISeq < 'T >) =
@@ -249,7 +242,7 @@ namespace Microsoft.FSharp.Collections
249
242
if this.State.MoveNext() then
250
243
f value this.State.Current
251
244
else
252
- ( Upcast.outOfBand this) .StopFurtherProcessing pipeIdx
245
+ ( this :> IOutOfBand ) .StopFurtherProcessing pipeIdx
253
246
Unchecked.defaultof<_> (* return value unused in Fold context *)
254
247
255
248
override this.OnComplete _ = ()
@@ -265,7 +258,7 @@ namespace Microsoft.FSharp.Collections
265
258
this.State._ 1 <- this.State._ 1 + 1
266
259
Unchecked.defaultof<_>
267
260
else
268
- ( Upcast.outOfBand this) .StopFurtherProcessing pipeIdx
261
+ ( this :> IOutOfBand ) .StopFurtherProcessing pipeIdx
269
262
Unchecked.defaultof<_>
270
263
override this.OnComplete _ = ()
271
264
override this.OnDispose () = this.State._ 2.Dispose () })
@@ -276,7 +269,7 @@ namespace Microsoft.FSharp.Collections
276
269
{ new Folder< 'T, Option< 'T>> ( None) with
277
270
override this.ProcessNext value =
278
271
this.Result <- Some value
279
- ( Upcast.outOfBand this) .StopFurtherProcessing pipeIdx
272
+ ( this :> IOutOfBand ) .StopFurtherProcessing pipeIdx
280
273
Unchecked.defaultof<_> (* return value unused in Fold context *) })
281
274
282
275
[<CompiledName " Head" >]
@@ -310,7 +303,7 @@ namespace Microsoft.FSharp.Collections
310
303
override this.ProcessNext value =
311
304
if f value then
312
305
this.Result <- true
313
- ( Upcast.outOfBand this) .StopFurtherProcessing pipeIdx
306
+ ( this :> IOutOfBand ) .StopFurtherProcessing pipeIdx
314
307
Unchecked.defaultof<_> (* return value unused in Fold context *) })
315
308
316
309
[<CompiledName " Exists2" >]
@@ -321,9 +314,9 @@ namespace Microsoft.FSharp.Collections
321
314
if this.State.MoveNext() then
322
315
if predicate value this.State.Current then
323
316
this.Result <- true
324
- ( Upcast.outOfBand this) .StopFurtherProcessing pipeIdx
317
+ ( this :> IOutOfBand ) .StopFurtherProcessing pipeIdx
325
318
else
326
- ( Upcast.outOfBand this) .StopFurtherProcessing pipeIdx
319
+ ( this :> IOutOfBand ) .StopFurtherProcessing pipeIdx
327
320
Unchecked.defaultof<_> (* return value unused in Fold context *)
328
321
329
322
override this.OnComplete _ = ()
@@ -336,7 +329,7 @@ namespace Microsoft.FSharp.Collections
336
329
override this.ProcessNext value =
337
330
if element = value then
338
331
this.Result <- true
339
- ( Upcast.outOfBand this) .StopFurtherProcessing pipeIdx
332
+ ( this :> IOutOfBand ) .StopFurtherProcessing pipeIdx
340
333
Unchecked.defaultof<_> (* return value unused in Fold context *) })
341
334
342
335
[<CompiledName " ForAll" >]
@@ -346,7 +339,7 @@ namespace Microsoft.FSharp.Collections
346
339
override this.ProcessNext value =
347
340
if not ( predicate value) then
348
341
this.Result <- false
349
- ( Upcast.outOfBand this) .StopFurtherProcessing pipeIdx
342
+ ( this :> IOutOfBand ) .StopFurtherProcessing pipeIdx
350
343
Unchecked.defaultof<_> (* return value unused in Fold context *) })
351
344
352
345
[<CompiledName " ForAll2" >]
@@ -357,9 +350,9 @@ namespace Microsoft.FSharp.Collections
357
350
if this.State.MoveNext() then
358
351
if not ( predicate value this.State.Current) then
359
352
this.Result <- false
360
- ( Upcast.outOfBand this) .StopFurtherProcessing pipeIdx
353
+ ( this :> IOutOfBand ) .StopFurtherProcessing pipeIdx
361
354
else
362
- ( Upcast.outOfBand this) .StopFurtherProcessing pipeIdx
355
+ ( this :> IOutOfBand ) .StopFurtherProcessing pipeIdx
363
356
Unchecked.defaultof<_> (* return value unused in Fold context *)
364
357
365
358
override this.OnComplete _ = ()
@@ -447,12 +440,12 @@ namespace Microsoft.FSharp.Collections
447
440
override this.ProcessNext value =
448
441
if not ( this.State.MoveNext()) then
449
442
this.Result <- 1
450
- ( Upcast.outOfBand this) .StopFurtherProcessing pipeIdx
443
+ ( this :> IOutOfBand ) .StopFurtherProcessing pipeIdx
451
444
else
452
445
let c = f value this.State.Current
453
446
if c <> 0 then
454
447
this.Result <- c
455
- ( Upcast.outOfBand this) .StopFurtherProcessing pipeIdx
448
+ ( this :> IOutOfBand ) .StopFurtherProcessing pipeIdx
456
449
Unchecked.defaultof<_> (* return value unused in Fold context *)
457
450
override this.OnComplete _ =
458
451
if this.Result = 0 && this.State.MoveNext() then
@@ -597,7 +590,7 @@ namespace Microsoft.FSharp.Collections
597
590
598
591
[<CompiledName( " Concat" ) >]
599
592
let concat ( sources : ISeq < #ISeq < 'T >>) : ISeq < 'T > =
600
- Upcast.seq ( ThinConcatEnumerable ( sources, id))
593
+ upcast ( ThinConcatEnumerable ( sources, id))
601
594
602
595
[<CompiledName " Scan" >]
603
596
let inline scan ( folder : 'State -> 'T -> 'State ) ( initialState : 'State ) ( source : ISeq < 'T >) : ISeq < 'State > =
@@ -788,7 +781,7 @@ namespace Microsoft.FSharp.Collections
788
781
match f value with
789
782
| ( Some _) as some ->
790
783
this.Result <- some
791
- ( Upcast.outOfBand this) .StopFurtherProcessing pipeIdx
784
+ ( this :> IOutOfBand ) .StopFurtherProcessing pipeIdx
792
785
| None -> ()
793
786
Unchecked.defaultof<_> (* return value unused in Fold context *) })
794
787
@@ -799,7 +792,7 @@ namespace Microsoft.FSharp.Collections
799
792
override this.ProcessNext value =
800
793
if f value then
801
794
this.Result <- Some value
802
- ( Upcast.outOfBand this) .StopFurtherProcessing pipeIdx
795
+ ( this :> IOutOfBand ) .StopFurtherProcessing pipeIdx
803
796
Unchecked.defaultof<_> (* return value unused in Fold context *) })
804
797
805
798
[<CompiledName " TryFindIndex" >]
@@ -810,7 +803,7 @@ namespace Microsoft.FSharp.Collections
810
803
override this.ProcessNext value =
811
804
if predicate value then
812
805
this.Result <- Some this.State
813
- ( Upcast.outOfBand this) .StopFurtherProcessing pipeIdx
806
+ ( this :> IOutOfBand ) .StopFurtherProcessing pipeIdx
814
807
else
815
808
this.State <- this.State + 1
816
809
Unchecked.defaultof<_> (* return value unused in Fold context *) })
@@ -874,11 +867,11 @@ namespace Microsoft.FSharp.Collections
874
867
let append ( source1 : ISeq < 'T >) ( source2 : ISeq < 'T >) : ISeq < 'T > =
875
868
match source1 with
876
869
| :? EnumerableBase< 'T> as s -> s.Append source2
877
- | _ -> Upcast.seq ( new AppendEnumerable<_>([ source2; source1]))
870
+ | _ -> upcast ( new AppendEnumerable<_>([ source2; source1]))
878
871
879
872
[<CompiledName " Delay" >]
880
- let delay ( delayed : unit -> ISeq < 'T >) =
881
- Upcast.seq ( DelayedEnumerable ( delayed, 1 ))
873
+ let delay ( delayed : unit -> ISeq < 'T >) : ISeq < 'T > =
874
+ upcast ( DelayedEnumerable ( delayed, 1 ))
882
875
883
876
module internal GroupBy =
884
877
let inline private impl ( comparer : IEqualityComparer < 'SafeKey >) ( keyf : 'T -> 'SafeKey ) ( getKey : 'SafeKey -> 'Key ) ( source : ISeq < 'T >) =
@@ -1094,7 +1087,7 @@ namespace Microsoft.FSharp.Collections
1094
1087
else
1095
1088
None)
1096
1089
1097
- let cached = Upcast.seq ( new UnfoldEnumerable< 'T, 'T, int>( unfolding, 0 , IdentityFactory.Instance, 1 ))
1090
+ let cached : ISeq < 'T > = upcast ( new UnfoldEnumerable< 'T, 'T, int>( unfolding, 0 , IdentityFactory.Instance, 1 ))
1098
1091
1099
1092
interface System.IDisposable with
1100
1093
member __.Dispose () =
@@ -1111,7 +1104,7 @@ namespace Microsoft.FSharp.Collections
1111
1104
member __.GetEnumerator () = cached.GetEnumerator()
1112
1105
1113
1106
interface System.Collections.IEnumerable with
1114
- member __.GetEnumerator () = ( Upcast.enumerableNonGeneric cached) .GetEnumerator()
1107
+ member __.GetEnumerator () = ( cached:> IEnumerable ) .GetEnumerator()
1115
1108
1116
1109
interface ISeq< 'T> with
1117
1110
member __.PushTransform next = cached.PushTransform next
@@ -1121,7 +1114,7 @@ namespace Microsoft.FSharp.Collections
1121
1114
1122
1115
[<CompiledName( " Cache" ) >]
1123
1116
let cache ( source : ISeq < 'T >) : ISeq < 'T > =
1124
- Upcast.seq ( new CachedSeq<_> ( source))
1117
+ upcast ( new CachedSeq<_> ( source))
1125
1118
1126
1119
[<CompiledName( " Collect" ) >]
1127
1120
let collect f sources = map f sources |> concat
@@ -1140,9 +1133,9 @@ namespace Microsoft.FSharp.Collections
1140
1133
| _ -> Microsoft.FSharp.Primitives.Basics.List.ofISeq source
1141
1134
1142
1135
[<CompiledName( " Replicate" ) >]
1143
- let replicate count x =
1136
+ let replicate < 'T > count ( x : 'T ) : ISeq < 'T > =
1144
1137
if count < 0 then raise ( ArgumentOutOfRangeException " count" )
1145
- Upcast.seq ( new InitEnumerable< 'T, 'T>( Nullable count, ( fun _ -> x), IdentityFactory.Instance, 1 ))
1138
+ upcast ( new InitEnumerable< 'T, 'T>( Nullable count, ( fun _ -> x), IdentityFactory.Instance, 1 ))
1146
1139
1147
1140
[<CompiledName( " IsEmpty" ) >]
1148
1141
let isEmpty ( source : ISeq < 'T >) =
0 commit comments