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

Commita0ccf49

Browse files
PatrickMcDonaldlatkin
authored andcommitted
Implement Array.skip, List.skip
commit ed3135a57cbed377714c18523ea62ba3d297dd90Author: latkin <latkin@microsoft.com>Date: Mon Oct 20 16:59:00 2014 -0700 Changing behavior to match Seq.skip - treat negative count same as 0. Also expanding testscommit 14bed2524158501f5157d93679338b521b15d3acAuthor: latkin <latkin@microsoft.com>Date: Mon Oct 20 16:32:05 2014 -0700 Small optimizations and fix for List docscommit 7e681d5149f99c1270a1e981d7a560ba63db3f82Merge:ef4388f ee08264Author: latkin <latkin@microsoft.com>Date: Mon Oct 20 16:23:49 2014 -0700 Merge branch 'skip' ofhttps://git01.codeplex.com/forks/patrickmcdonald/visualfsharp into PR_skip Conflicts: src/fsharp/FSharp.Core.Unittests/SurfaceArea.4.0.fs src/fsharp/FSharp.Core.Unittests/SurfaceArea.Portable.fs src/fsharp/FSharp.Core/list.fsicommit ee08264d59c31743bf8275ad72b1edad5bdde7baAuthor: Patrick McDonald <paddymcdonald@gmail.com>Date: Mon Sep 8 12:15:43 2014 +0100 Use array slicing for Array.skipcommit d9fe92c9d2e2860065154cc49377fc2b262d3bfeAuthor: Patrick McDonald <paddymcdonald@gmail.com>Date: Thu Aug 14 00:29:00 2014 +0100 Fix surface area portable testscommit 1f2fab6ca603f04e186d6ef041decbe0c35b929aAuthor: Patrick McDonald <paddymcdonald@gmail.com>Date: Fri Aug 8 01:25:21 2014 +0100 Implement List.skip and Array.skip
1 parentef4388f commita0ccf49

File tree

8 files changed

+100
-0
lines changed

8 files changed

+100
-0
lines changed

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,34 @@ type ArrayModule2() =
445445

446446
()
447447

448+
[<Test>]
449+
memberthis.Skip()=
450+
// integer array
451+
letresultInt= Array.skip2[|1..10|]
452+
if resultInt<>[|3..10|]then Assert.Fail()
453+
454+
letresultInt2= Array.skip0[|1..10|]
455+
if resultInt2<>[|1..10|]then Assert.Fail()
456+
457+
letresultInt3= Array.skip-5[|1..10|]
458+
if resultInt3<>[|1..10|]then Assert.Fail()
459+
460+
// string List
461+
letresultStr= Array.skip2[|"str1";"str2";"str3";"str4"|]
462+
if resultStr<>[|"str3";"str4"|]then Assert.Fail()
463+
464+
// empty List
465+
letresultEpt= Array.skip0[||]
466+
if resultEpt<>[||]then Assert.Fail()
467+
468+
// exceptions
469+
CheckThrowsArgumentNullException(fun()-> Array.skip0(null:string[])|> ignore)
470+
CheckThrowsArgumentNullException(fun()-> Array.skip-3(null:string[])|> ignore)
471+
CheckThrowsArgumentException(fun()-> Array.skip1[||]|> ignore)
472+
CheckThrowsArgumentException(fun()-> Array.skip4[|1;2;3|]|> ignore)
473+
474+
()
475+
448476
[<Test>]
449477
memberthis.Set()=
450478
// integer array

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,32 @@ type ListModule02() =
426426

427427
()
428428

429+
[<Test>]
430+
memberthis.Skip()=
431+
// integer List
432+
letresultInt= List.skip2[1..10]
433+
Assert.AreEqual([3..10], resultInt)
434+
435+
letresultInt2= List.skip0[1..10]
436+
Assert.AreEqual([1..10], resultInt2)
437+
438+
letresultInt3= List.skip-1[1..10]
439+
Assert.AreEqual([1..10], resultInt3)
440+
441+
// string List
442+
letresultStr= List.skip2["str1";"str2";"str3";"str4"]
443+
Assert.AreEqual(["str3";"str4"], resultStr)
444+
445+
// empty List
446+
letresultEpt= List.skip0[]
447+
Assert.AreEqual([], resultEpt)
448+
449+
// exceptions
450+
CheckThrowsArgumentException(fun()-> List.skip1[]|> ignore)
451+
CheckThrowsArgumentException(fun()-> List.skip4[1;2;3]|> ignore)
452+
453+
()
454+
429455
[<Test>]
430456
memberthis.Sort()=
431457
// integer List

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ Microsoft.FSharp.Collections.ArrayModule: T[] Permute[T](Microsoft.FSharp.Core.F
168168
Microsoft.FSharp.Collections.ArrayModule: T[] Replicate[T](Int32, T)
169169
Microsoft.FSharp.Collections.ArrayModule: T[] Reverse[T](T[])
170170
Microsoft.FSharp.Collections.ArrayModule: T[] Singleton[T](T)
171+
Microsoft.FSharp.Collections.ArrayModule: T[] Skip[T](Int32, T[])
171172
Microsoft.FSharp.Collections.ArrayModule: T[] SortBy[T,TKey](Microsoft.FSharp.Core.FSharpFunc`2[T,TKey], T[])
172173
Microsoft.FSharp.Collections.ArrayModule: T[] SortWith[T](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpFunc`2[T,System.Int32]], T[])
173174
Microsoft.FSharp.Collections.ArrayModule: T[] Sort[T](T[])
@@ -312,6 +313,7 @@ Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList
312313
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] Replicate[T](Int32, T)
313314
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] Reverse[T](Microsoft.FSharp.Collections.FSharpList`1[T])
314315
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] Singleton[T](T)
316+
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] Skip[T](Int32, Microsoft.FSharp.Collections.FSharpList`1[T])
315317
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] SortBy[T,TKey](Microsoft.FSharp.Core.FSharpFunc`2[T,TKey], Microsoft.FSharp.Collections.FSharpList`1[T])
316318
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] SortWith[T](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpFunc`2[T,System.Int32]], Microsoft.FSharp.Collections.FSharpList`1[T])
317319
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] Sort[T](Microsoft.FSharp.Collections.FSharpList`1[T])

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ Microsoft.FSharp.Collections.ArrayModule: T[] Permute[T](Microsoft.FSharp.Core.F
162162
Microsoft.FSharp.Collections.ArrayModule: T[] Replicate[T](Int32, T)
163163
Microsoft.FSharp.Collections.ArrayModule: T[] Reverse[T](T[])
164164
Microsoft.FSharp.Collections.ArrayModule: T[] Singleton[T](T)
165+
Microsoft.FSharp.Collections.ArrayModule: T[] Skip[T](Int32, T[])
165166
Microsoft.FSharp.Collections.ArrayModule: T[] SortBy[T,TKey](Microsoft.FSharp.Core.FSharpFunc`2[T,TKey], T[])
166167
Microsoft.FSharp.Collections.ArrayModule: T[] SortWith[T](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpFunc`2[T,System.Int32]], T[])
167168
Microsoft.FSharp.Collections.ArrayModule: T[] Sort[T](T[])
@@ -306,6 +307,7 @@ Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList
306307
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] Replicate[T](Int32, T)
307308
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] Reverse[T](Microsoft.FSharp.Collections.FSharpList`1[T])
308309
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] Singleton[T](T)
310+
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] Skip[T](Int32, Microsoft.FSharp.Collections.FSharpList`1[T])
309311
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] SortBy[T,TKey](Microsoft.FSharp.Core.FSharpFunc`2[T,TKey], Microsoft.FSharp.Collections.FSharpList`1[T])
310312
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] SortWith[T](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpFunc`2[T,System.Int32]], Microsoft.FSharp.Collections.FSharpList`1[T])
311313
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] Sort[T](Microsoft.FSharp.Collections.FSharpList`1[T])

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,19 @@ namespace Microsoft.FSharp.Collections
460460
if f array.[i]then Some array.[i]else loop(i+1)
461461
loop0
462462

463+
[<CompiledName("Skip")>]
464+
letskip count(array:'T[])=
465+
checkNonNull"array" array
466+
if count> array.Lengththen invalidArg"count"(SR.GetString(SR.outOfRange))
467+
if count= array.Lengththen
468+
[||]
469+
else
470+
letcount= max count0
471+
letskippedLen= array.Length- count
472+
letres:'T[]= Microsoft.FSharp.Primitives.Basics.Array.zeroCreateUnchecked skippedLen
473+
Array.Copy(array, count, res,0, skippedLen)
474+
res
475+
463476
[<CompiledName("Zip")>]
464477
letzip(array1:_[])(array2:_[])=
465478
checkNonNull"array1" array1

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,16 @@ namespace Microsoft.FSharp.Collections
626626
[<CompiledName("Set")>]
627627
val set:array:'T[]->index:int->value:'T->unit
628628

629+
///<summary>Builds a new array that contains the elements of the given array,excluding the first N elements.</summary>
630+
///<param name="count">The number of elements to skip.</param>
631+
///<param name="array">The input array.</param>
632+
///<returns>A copy of the input array,after removing the first N elements.</returns>
633+
///<exception cref="System.ArgumentNullException">Thrown when the input array is null.</exception>
634+
///<exception cref="System.ArgumentExcepion">Thrown when count is negative or exceeds the number of
635+
///elements in the array.</exception>
636+
[<CompiledName("Skip")>]
637+
val skip:count:int->array:'T[]-> 'T[]
638+
629639
///<summary>Builds a new array that contains the given subrange specified by
630640
///starting index and length.</summary>
631641
///<param name="array">The input array.</param>

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,16 @@ namespace Microsoft.FSharp.Collections
400400
[<CompiledName("Zip3")>]
401401
letzip3 x1 x2 x3= Microsoft.FSharp.Primitives.Basics.List.zip3 x1 x2 x3
402402

403+
[<CompiledName("Skip")>]
404+
letskip count list=
405+
if count<=0then listelse
406+
let recloop i lst=
407+
match lstwith
408+
|_when i=0-> lst
409+
|_::t-> loop(i-1) t
410+
|[]-> invalidArg"count"(SR.GetString(SR.outOfRange))
411+
loop count list
412+
403413
[<CompiledName("SortWith")>]
404414
letsortWith cmp xs= Microsoft.FSharp.Primitives.Basics.List.sortWith cmp xs
405415

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,15 @@ namespace Microsoft.FSharp.Collections
541541
[<CompiledName("Singleton")>]
542542
val inline singleton:value:'T-> 'T list
543543

544+
///<summary>Returns the list after removing the first N elements.</summary>
545+
///<param name="count">The number of elements to skip.</param>
546+
///<param name="list">The input list.</param>
547+
///<returns>The list after removing the first N elements.</returns>
548+
///<exception cref="System.ArgumentException">Thrown when count is negative or exceeds the number of
549+
///elements in the list.</exception>
550+
[<CompiledName("Skip")>]
551+
val skip:count:int->list: 'T list-> 'T list
552+
544553
///<summary>Sorts the given list using the given comparison function.</summary>
545554
///
546555
///<remarks>This is a stable sort,i.e. the original order of equal elements is preserved.</remarks>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp