Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita870b96

Browse files
Rename and reorder extract input parameters
Change itemsToExclude from M(T) to seq<T>
1 parent646db39 commita870b96

File tree

10 files changed

+67
-48
lines changed

10 files changed

+67
-48
lines changed

‎src/fsharp/FSharp.Core.Unittests/FSharp.Core/Microsoft.FSharp.Collections/ArrayModule.fs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,19 +194,19 @@ type ArrayModule() =
194194
letintArr2=[|1..10|]
195195
letexpectedIntArr=[|11..100|]
196196

197-
Assert.AreEqual(expectedIntArr, Array.exceptintArr1intArr2)
197+
Assert.AreEqual(expectedIntArr, Array.except intArr2 intArr1)
198198

199199
// string array
200200
letstrArr1=[|"a";"b";"c";"d";"a"|]
201201
letstrArr2=[|"b";"c"|]
202202
letexpectedStrArr=[|"a";"d"|]
203203

204-
Assert.AreEqual(expectedStrArr, Array.exceptstrArr1strArr2)
204+
Assert.AreEqual(expectedStrArr, Array.except strArr2 strArr1)
205205

206206
// empty array
207207
letemptyIntArr=[||]
208-
Assert.AreEqual([|1..100|], Array.exceptintArr1emptyIntArr)
209-
Assert.AreEqual(emptyIntArr, Array.exceptemptyIntArrintArr1)
208+
Assert.AreEqual([|1..100|], Array.except emptyIntArr intArr1)
209+
Assert.AreEqual(emptyIntArr, Array.except intArr1 emptyIntArr)
210210
Assert.AreEqual(emptyIntArr, Array.except emptyIntArr emptyIntArr)
211211
Assert.AreEqual(emptyIntArr, Array.except intArr1 intArr1)
212212

‎src/fsharp/FSharp.Core.Unittests/FSharp.Core/Microsoft.FSharp.Collections/ListModule.fs‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -282,22 +282,25 @@ type ListModule() =
282282
letintList2=[1..10]
283283
letexpectedIntList=[11..100]
284284

285-
Assert.AreEqual(expectedIntList, List.exceptintList1intList2)
285+
Assert.AreEqual(expectedIntList, List.except intList2 intList1)
286286

287287
// string list
288288
letstrList1=["a";"b";"c";"d";"a"]
289289
letstrList2=["b";"c"]
290290
letexpectedStrList=["a";"d"]
291291

292-
Assert.AreEqual(expectedStrList, List.exceptstrList1strList2)
292+
Assert.AreEqual(expectedStrList, List.except strList2 strList1)
293293

294294
// empty list
295295
letemptyIntList=[]
296-
Assert.AreEqual([1..100], List.exceptintList1emptyIntList)
297-
Assert.AreEqual(emptyIntList, List.exceptemptyIntListintList1)
296+
Assert.AreEqual([1..100], List.except emptyIntList intList1)
297+
Assert.AreEqual(emptyIntList, List.except intList1 emptyIntList)
298298
Assert.AreEqual(emptyIntList, List.except emptyIntList emptyIntList)
299299
Assert.AreEqual(emptyIntList, List.except intList1 intList1)
300300

301+
// null seq
302+
letnullSeq:int[]=null
303+
CheckThrowsArgumentNullException(fun()-> List.except nullSeq emptyIntList|> ignore)
301304
()
302305

303306
[<Test>]

‎src/fsharp/FSharp.Core.Unittests/FSharp.Core/Microsoft.FSharp.Collections/SeqModule.fs‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -486,19 +486,26 @@ type SeqModule() =
486486
letintSeq2={1..10}
487487
letexpectedIntSeq={11..100}
488488

489-
VerifySeqsEqual expectedIntSeq<| Seq.exceptintSeq1intSeq2
489+
VerifySeqsEqual expectedIntSeq<| Seq.except intSeq2 intSeq1
490490

491491
// string Seq
492492
letstrSeq1= seq["a";"b";"c";"d";"a"]
493493
letstrSeq2= seq["b";"c"]
494494
letexpectedStrSeq= seq["a";"d"]
495495

496-
VerifySeqsEqual expectedStrSeq<| Seq.except strSeq1 strSeq2
496+
VerifySeqsEqual expectedStrSeq<| Seq.except strSeq2 strSeq1
497+
498+
// double Seq
499+
// Sequences with nan do not behave, due to the F# generic equality comparisons
500+
// let floatSeq1 = seq [1.0; 1.0; System.Double.MaxValue; nan; nan]
501+
//
502+
// VerifySeqsEqual [1.0; System.Double.MaxValue; nan; nan] <| Seq.except [] floatSeq1
503+
// VerifySeqsEqual [1.0; System.Double.MaxValue] <| Seq.except [nan] floatSeq1
497504

498505
// empty Seq
499506
letemptyIntSeq= Seq.empty<int>
500-
VerifySeqsEqual{1..100}<| Seq.exceptintSeq1emptyIntSeq
501-
VerifySeqsEqual emptyIntSeq<| Seq.exceptemptyIntSeqintSeq1
507+
VerifySeqsEqual{1..100}<| Seq.except emptyIntSeq intSeq1
508+
VerifySeqsEqual emptyIntSeq<| Seq.except intSeq1 emptyIntSeq
502509
VerifySeqsEqual emptyIntSeq<| Seq.except emptyIntSeq emptyIntSeq
503510
VerifySeqsEqual emptyIntSeq<| Seq.except intSeq1 intSeq1
504511

‎src/fsharp/FSharp.Core.Unittests/SurfaceArea.net40.fs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ Microsoft.FSharp.Collections.ArrayModule: T[] Create[T](Int32, T)
149149
Microsoft.FSharp.Collections.ArrayModule: T[] DistinctBy[T,TKey](Microsoft.FSharp.Core.FSharpFunc`2[T,TKey], T[])
150150
Microsoft.FSharp.Collections.ArrayModule: T[] Distinct[T](T[])
151151
Microsoft.FSharp.Collections.ArrayModule: T[] Empty[T]()
152-
Microsoft.FSharp.Collections.ArrayModule: T[] Except[T](T[], T[])
152+
Microsoft.FSharp.Collections.ArrayModule: T[] Except[T](System.Collections.Generic.IEnumerable`1[T], T[])
153153
Microsoft.FSharp.Collections.ArrayModule: T[] Filter[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean], T[])
154154
Microsoft.FSharp.Collections.ArrayModule: T[] GetSubArray[T](T[], Int32, Int32)
155155
Microsoft.FSharp.Collections.ArrayModule: T[] Initialize[T](Int32, Microsoft.FSharp.Core.FSharpFunc`2[System.Int32,T])
@@ -310,7 +310,7 @@ Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList
310310
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] DistinctBy[T,TKey](Microsoft.FSharp.Core.FSharpFunc`2[T,TKey], Microsoft.FSharp.Collections.FSharpList`1[T])
311311
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] Distinct[T](Microsoft.FSharp.Collections.FSharpList`1[T])
312312
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] Empty[T]()
313-
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] Except[T](Microsoft.FSharp.Collections.FSharpList`1[T], Microsoft.FSharp.Collections.FSharpList`1[T])
313+
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] Except[T](System.Collections.Generic.IEnumerable`1[T], Microsoft.FSharp.Collections.FSharpList`1[T])
314314
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] Filter[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean], Microsoft.FSharp.Collections.FSharpList`1[T])
315315
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] Initialize[T](Int32, Microsoft.FSharp.Core.FSharpFunc`2[System.Int32,T])
316316
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] OfArray[T](T[])

‎src/fsharp/FSharp.Core/array.fs‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -479,15 +479,15 @@ namespace Microsoft.FSharp.Collections
479479
letwhere f(array:_[])= filter f array
480480

481481
[<CompiledName("Except")>]
482-
letexcept(array1:'T[])(array2:'T[])=
483-
checkNonNull"array1" array1
484-
checkNonNull"array2" array2
482+
letexcept(itemsToExclude:seq<_>)(array:_[])=
483+
checkNonNull"itemsToExclude" itemsToExclude
484+
checkNonNull"array" array
485485

486-
ifarray1.Length=0then
487-
array1
486+
ifarray.Length=0then
487+
array
488488
else
489-
letcached= HashSet(array2, HashIdentity.Structural)
490-
filter(fun item-> cached.Add item)array1
489+
letcached= HashSet(itemsToExclude, HashIdentity.Structural)
490+
filter(fun item-> cached.Add item)array
491491

492492
[<CompiledName("Partition")>]
493493
letpartition f(array:_[])=

‎src/fsharp/FSharp.Core/array.fsi‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -216,17 +216,18 @@ namespace Microsoft.FSharp.Collections
216216
[<CompiledName("ExactlyOne")>]
217217
val exactlyOne:array:'T[]-> 'T
218218

219-
///<summary>Produces the set difference of two arrays by using generic hash and equality comparisons to compare values.</summary>
219+
///<summary>Returns a new list with the distinct elements of the input array which do not appear in the itemsToExclude sequence,
220+
///using generic hash and equality comparisons to compare values.</summary>
220221
///
221-
///<param name="array1">An array whose elements that are not also in second will be returned.</param>
222-
///<param name="array2">A second array whose elements that also occur in the first array will cause those elements to be
222+
///<param name="itemsToExclude">A sequence whose elements that also occur in the input array will cause those elements to be
223223
///removed from the result.</param>
224+
///<param name="array">An array whose elements that are not also in itemsToExclude will be returned.</param>
224225
///
225-
///<returns>An array that contains theset difference ofthe elements of two arrays.</returns>
226+
///<returns>An array that contains thedistinct elements of<c>array</c> that do not appear in <c>itemsToExclude</c>.</returns>
226227
///
227-
///<exception cref="System.ArgumentNullException">Thrown when eitherof the two input arrays is null.</exception>
228+
///<exception cref="System.ArgumentNullException">Thrown when eitheritemsToExclude or array is null.</exception>
228229
[<CompiledName("Except")>]
229-
val except:array1:'T[]->array2:'T[]-> 'T[]when 'T:equality
230+
val except:itemsToExclude:seq<'T>->array:'T[]-> 'T[]when 'T:equality
230231

231232
///<summary>Tests if any element of the array satisfies the given predicate.</summary>
232233
///

‎src/fsharp/FSharp.Core/list.fs‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -420,12 +420,16 @@ namespace Microsoft.FSharp.Collections
420420
letfilter f x= Microsoft.FSharp.Primitives.Basics.List.filter f x
421421

422422
[<CompiledName("Except")>]
423-
letexcept list1(list2:_ list)=
424-
match list1, list2with
425-
|[],_-> list1
423+
letexcept itemsToExclude list=
424+
match box itemsToExcludewith
425+
|null-> nullArg"itemsToExclude"
426+
|_->()
427+
428+
match listwith
429+
|[]-> list
426430
|_->
427-
letcached= HashSet(list2, HashIdentity.Structural)
428-
list1|> filter(fun item-> cached.Add item)
431+
letcached= HashSet(itemsToExclude, HashIdentity.Structural)
432+
list|> filter(fun item-> cached.Add item)
429433

430434
[<CompiledName("Where")>]
431435
letwhere f x= Microsoft.FSharp.Primitives.Basics.List.filter f x

‎src/fsharp/FSharp.Core/list.fsi‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,15 +125,18 @@ namespace Microsoft.FSharp.Collections
125125
[<CompiledName("Empty")>]
126126
val empty<'T>: 'T list
127127

128-
///<summary>Produces the set difference of two lists by using generic hash and equality comparisons to compare values.</summary>
128+
///<summary>Returns a new list with the distinct elements of the input list which do not appear in the itemsToExclude sequence,
129+
///using generic hash and equality comparisons to compare values.</summary>
129130
///
130-
///<param name="list1">A list whose elements that are not also in second will be returned.</param>
131-
///<param name="list2">A second list whose elements that also occur in the first list will cause those elements to be
131+
///<param name="itemsToExclude">A sequence whose elements that also occur in the input list will cause those elements to be
132132
///removed from the result.</param>
133+
///<param name="list">A list whose elements that are not also in itemsToExclude will be returned.</param>
133134
///
134-
///<returns>A list that contains the set difference of the elements of two lists.</returns>
135+
///<returns>A list that contains the distinct elements of <c>list</c> that do not appear in <c>itemsToExclude</c>.</returns>
136+
///
137+
///<exception cref="System.ArgumentNullException">Thrown when itemsToExclude is null.</exception>
135138
[<CompiledName("Except")>]
136-
val except:list1:'T list->list2:'T list-> 'T list when 'T:equality
139+
val except:itemsToExclude:seq<'T>->list:'T list-> 'T list when 'T:equality
137140

138141
///<summary>Returns the only element of the list.</summary>
139142
///

‎src/fsharp/FSharp.Core/seq.fs‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1815,14 +1815,14 @@ namespace Microsoft.FSharp.Collections
18151815
readonly arr, state
18161816

18171817
[<CompiledName("Except")>]
1818-
letexcept(source1:seq<'T>)(source2:seq<'T>)=
1819-
checkNonNull"source1" source1
1820-
checkNonNull"source2" source2
1818+
letexcept(itemsToExclude:seq<'T>)(source:seq<'T>)=
1819+
checkNonNull"itemsToExclude" itemsToExclude
1820+
checkNonNull"source" source
18211821

18221822
seq{
1823-
use e=source1.GetEnumerator()
1823+
use e=source.GetEnumerator()
18241824
if e.MoveNext()then
1825-
letcached= HashSet(source2)
1825+
letcached= HashSet(itemsToExclude, HashIdentity.Structural)
18261826
letnext= e.Current
18271827
if(cached.Add next)thenyield next
18281828
while e.MoveNext()do

‎src/fsharp/FSharp.Core/seq.fsi‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -243,22 +243,23 @@ namespace Microsoft.FSharp.Collections
243243
[<CompiledName("Empty")>]
244244
val empty<'T>:seq<'T>
245245

246-
///<summary>Produces the set difference of two sequences by using generic hash and equality comparisons to compare values.</summary>
246+
///<summary>Returns a new sequence with the distinct elements of the second sequence which do not apear in the first sequence,
247+
///using generic hash and equality comparisons to compare values.</summary>
247248
///
248-
///<remarks>Note that this function returns a sequence that digests the whole of thesecond input sequence as soon as
249+
///<remarks>Note that this function returns a sequence that digests the whole of thefirst input sequence as soon as
249250
///the result sequence is iterated. As a result this function should not be used with
250-
///large or infinite sequences. The function makes no assumption on the ordering of thesecond input
251+
///large or infinite sequences in the first parameter. The function makes no assumption on the ordering of thefirst input
251252
///sequence.</remarks>
252253
///
253-
///<param name="source1">A sequence whose elements that are not also in second will be returned.</param>
254-
///<param name="source2">A second sequence whose elements that also occur in the first sequence will cause those elements to be
254+
///<param name="itemsToExclude">A sequence whose elements that also occur in the second sequence will cause those elements to be
255255
///removed from the returned sequence.</param>
256+
///<param name="source">A sequence whose elements that are not also in first will be returned.</param>
256257
///
257258
///<returns>A sequence that contains the set difference of the elements of two sequences.</returns>
258259
///
259260
///<exception cref="System.ArgumentNullException">Thrown when either of the two input sequences is null.</exception>
260261
[<CompiledName("Except")>]
261-
val except:source1:seq<'T>->source2:seq<'T>->seq<'T> when 'T:equality
262+
val except:itemsToExclude:seq<'T>->source:seq<'T>->seq<'T> when 'T:equality
262263

263264
///<summary>Tests if any element of the sequence satisfies the given predicate.</summary>
264265
///

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp