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

Commitf028ee4

Browse files
mexxlatkin
authored andcommitted
Implement Array.item, List.item, Seq.item
commit fef49e9f293499c24b30d919b7f5717f150b2c1cAuthor: latkin <latkin@microsoft.com>Date: Wed Oct 15 15:38:35 2014 -0700 Updating tests to use List/Seq.itemcommit beffde30280cdf7e03ddaf03f3830547e7c1616aAuthor: latkin <latkin@microsoft.com>Date: Wed Oct 15 15:19:45 2014 -0700 Change codebase to use List.item, Seq.item, to avoid deprecated warning. #nowarn added for those files which are proto-compiled (so we can't change to item yet)commit db122cc5416e106a8f2b1b32ad283b76e6741ff0Author: latkin <latkin@microsoft.com>Date: Wed Oct 15 14:18:41 2014 -0700 Validate input for Seq before calling GetEnumerator()commit e71caf605179083527617937941b7332c57b2f8eAuthor: latkin <latkin@microsoft.com>Date: Wed Oct 15 14:11:13 2014 -0700 Minor fixups to XML documentationcommit a42c5f1354c77caeab0a792f683712dc91720c61Merge:321dcde 4d20814Author: latkin <latkin@microsoft.com>Date: Sun Oct 12 13:24:42 2014 -0700 Merge branch 'item' ofhttps://git01.codeplex.com/forks/mexx24/visualfsharp into PR Conflicts: src/fsharp/FSharp.Core.Unittests/SurfaceArea.4.0.fs src/fsharp/FSharp.Core.Unittests/SurfaceArea.Portable.fs src/fsharp/FSharp.Core/array.fsicommit 4d20814a858a054a92545571c5f99501a26c1974Author: Max Malook <community@malook.de>Date: Thu Jul 10 02:03:36 2014 +0200 mark Seq.nth, List.nth and Array.get as obsoletecommit 73a6a55a6482a58be1da32a322e7743e41125125Author: Max Malook <community@malook.de>Date: Thu Jul 10 01:26:35 2014 +0200 add Array.item functioncommit d1dd69283ce3a8f6f6581313aff3fc9f3e4536d5Author: Max Malook <community@malook.de>Date: Thu Jul 10 01:09:00 2014 +0200 add List.item functioncommit a9c613e3b0c68155194fa7e8cd4badc3cfd4591cAuthor: Max Malook <community@malook.de>Date: Wed Jul 9 18:27:46 2014 +0200 add Seq.item function
1 parent3a27cd8 commitf028ee4

File tree

33 files changed

+184
-44
lines changed

33 files changed

+184
-44
lines changed

‎src/absil/il.fs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
moduleinternalMicrosoft.FSharp.Compiler.AbstractIL.IL
44

55
#nowarn"49"
6+
#nowarn"44"// This construct is deprecated. please use List.item
67
#nowarn"343"// The type 'ILAssemblyRef' implements 'System.IComparable' explicitly but provides no corresponding override for 'Object.Equals'.
78
#nowarn"346"// The struct, record or union type 'IlxExtensionType' has an explicit implementation of 'Object.Equals'. ...
89

‎src/absil/ilread.fs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
moduleinternalMicrosoft.FSharp.Compiler.AbstractIL.ILBinaryReader
99

1010
#nowarn"42"// This construct is deprecated: it is only for use in the F# library
11+
#nowarn"44"// This construct is deprecated. please use List.item
1112

1213
openSystem
1314
openSystem.IO

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -841,3 +841,28 @@ type ArrayModule2() =
841841
CheckThrowsArgumentException(fun()-> Array.zip3[|1..10|][|1..10|][|2..20|]|> ignore)
842842

843843
()
844+
845+
[<Test>]
846+
memberthis.Item()=
847+
// integer array
848+
letresultInt= Array.item3[|1..8|]
849+
Assert.AreEqual(4, resultInt)
850+
851+
// string array
852+
letresultStr= Array.item2[|"Arrays";"are";"commonly";"array"|]
853+
Assert.AreEqual("commonly", resultStr)
854+
855+
// empty array
856+
CheckThrowsIndexOutRangException(fun()-> Array.item0([||]: decimal[])|> ignore)
857+
858+
// null array
859+
letnullArr=null:string[]
860+
CheckThrowsNullRefException(fun()-> Array.item0 nullArr|> ignore)
861+
862+
// Negative index
863+
for i=-1downto-10do
864+
CheckThrowsIndexOutRangException(fun()-> Array.item i[|1..8|]|> ignore)
865+
866+
// Out of range
867+
for i=11to20do
868+
CheckThrowsIndexOutRangException(fun()-> Array.item i[|1..8|]|> ignore)

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

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Various tests for the:
44
// Microsoft.FSharp.Collections.List module
55

6+
#nowarn"44"// This construct is deprecated. please use List.item
67
namespaceFSharp.Core.Unittests.FSharp_Core.Microsoft_FSharp_Collections
78

89
openSystem
@@ -254,7 +255,28 @@ type ListModule02() =
254255
CheckThrowsArgumentException(fun()-> List.nth List.empty1)
255256

256257
()
257-
258+
259+
[<Test>]
260+
memberthis.Item()=
261+
// integer List
262+
letresultInt= List.item3[3;7;9;4;8;1;1;2]
263+
Assert.AreEqual(4, resultInt)
264+
265+
// string List
266+
letresultStr= List.item3["a";"b";"c";"d"]
267+
Assert.AreEqual("d", resultStr)
268+
269+
// empty List
270+
CheckThrowsArgumentException(fun()-> List.item1 List.empty)
271+
272+
// Negative index
273+
for i=-1downto-10do
274+
CheckThrowsArgumentException(fun()-> List.item i[3;7;9;4;8;1;1;2]|> ignore)
275+
276+
// Out of range
277+
for i=8to16do
278+
CheckThrowsArgumentException(fun()-> List.item i[3;7;9;4;8;1;1;2]|> ignore)
279+
258280

259281
[<Test>]
260282
memberthis.Of_Array()=

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

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Copyright (c) Microsoft Open Technologies, Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
22

3+
#nowarn"44"// This construct is deprecated. please use Seq.item
34
namespaceFSharp.Core.Unittests.FSharp_Core.Microsoft_FSharp_Collections
45

56
openSystem
@@ -784,7 +785,8 @@ type SeqModule2() =
784785
CheckThrowsArgumentNullException(fun()-> Seq.min nullSeq|> ignore)
785786

786787
()
787-
788+
789+
788790
[<Test>]
789791
memberthis.Nth()=
790792

@@ -812,7 +814,32 @@ type SeqModule2() =
812814
CheckThrowsArgumentNullException(fun()->Seq.nth3 nullSeq|> ignore)
813815

814816
()
815-
817+
818+
[<Test>]
819+
memberthis.Item()=
820+
// integer Seq
821+
letresultInt= Seq.item3{10..20}
822+
Assert.AreEqual(13, resultInt)
823+
824+
// string Seq
825+
letresultStr= Seq.item2(seq["Lists";"Are";"Cool";"List"])
826+
Assert.AreEqual("Cool", resultStr)
827+
828+
// empty Seq
829+
CheckThrowsArgumentException(fun()-> Seq.item0(Seq.empty: seq<decimal>)|> ignore)
830+
831+
// null Seq
832+
letnullSeq:seq<'a>=null
833+
CheckThrowsArgumentNullException(fun()->Seq.item3 nullSeq|> ignore)
834+
835+
// Negative index
836+
for i=-1downto-10do
837+
CheckThrowsArgumentException(fun()-> Seq.item i{10..20}|> ignore)
838+
839+
// Out of range
840+
for i=11to20do
841+
CheckThrowsArgumentException(fun()-> Seq.item i{10..20}|> ignore)
842+
816843
[<Test>]
817844
memberthis.Of_Array()=
818845
// integer Seq

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ Microsoft.FSharp.Collections.ArrayModule: T ExactlyOne[T](T[])
126126
Microsoft.FSharp.Collections.ArrayModule: T Find[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean], T[])
127127
Microsoft.FSharp.Collections.ArrayModule: T Get[T](T[], Int32)
128128
Microsoft.FSharp.Collections.ArrayModule: T Head[T](T[])
129+
Microsoft.FSharp.Collections.ArrayModule: T Item[T](Int32, T[])
129130
Microsoft.FSharp.Collections.ArrayModule: T Last[T](T[])
130131
Microsoft.FSharp.Collections.ArrayModule: T MaxBy[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,TResult], T[])
131132
Microsoft.FSharp.Collections.ArrayModule: T Max[T](T[])
@@ -333,6 +334,7 @@ Microsoft.FSharp.Collections.ListModule: T ExactlyOne[T](Microsoft.FSharp.Collec
333334
Microsoft.FSharp.Collections.ListModule: T Find[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean], Microsoft.FSharp.Collections.FSharpList`1[T])
334335
Microsoft.FSharp.Collections.ListModule: T Get[T](Microsoft.FSharp.Collections.FSharpList`1[T], Int32)
335336
Microsoft.FSharp.Collections.ListModule: T Head[T](Microsoft.FSharp.Collections.FSharpList`1[T])
337+
Microsoft.FSharp.Collections.ListModule: T Item[T](Int32, Microsoft.FSharp.Collections.FSharpList`1[T])
336338
Microsoft.FSharp.Collections.ListModule: T Last[T](Microsoft.FSharp.Collections.FSharpList`1[T])
337339
Microsoft.FSharp.Collections.ListModule: T MaxBy[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,TResult], Microsoft.FSharp.Collections.FSharpList`1[T])
338340
Microsoft.FSharp.Collections.ListModule: T Max[T](Microsoft.FSharp.Collections.FSharpList`1[T])
@@ -444,6 +446,7 @@ Microsoft.FSharp.Collections.SeqModule: T ExactlyOne[T](System.Collections.Gener
444446
Microsoft.FSharp.Collections.SeqModule: T Find[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean], System.Collections.Generic.IEnumerable`1[T])
445447
Microsoft.FSharp.Collections.SeqModule: T Get[T](Int32, System.Collections.Generic.IEnumerable`1[T])
446448
Microsoft.FSharp.Collections.SeqModule: T Head[T](System.Collections.Generic.IEnumerable`1[T])
449+
Microsoft.FSharp.Collections.SeqModule: T Item[T](Int32, System.Collections.Generic.IEnumerable`1[T])
447450
Microsoft.FSharp.Collections.SeqModule: T Last[T](System.Collections.Generic.IEnumerable`1[T])
448451
Microsoft.FSharp.Collections.SeqModule: T MaxBy[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,TResult], System.Collections.Generic.IEnumerable`1[T])
449452
Microsoft.FSharp.Collections.SeqModule: T Max[T](System.Collections.Generic.IEnumerable`1[T])

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ Microsoft.FSharp.Collections.ArrayModule: T ExactlyOne[T](T[])
120120
Microsoft.FSharp.Collections.ArrayModule: T Find[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean], T[])
121121
Microsoft.FSharp.Collections.ArrayModule: T Get[T](T[], Int32)
122122
Microsoft.FSharp.Collections.ArrayModule: T Head[T](T[])
123+
Microsoft.FSharp.Collections.ArrayModule: T Item[T](Int32, T[])
123124
Microsoft.FSharp.Collections.ArrayModule: T Last[T](T[])
124125
Microsoft.FSharp.Collections.ArrayModule: T MaxBy[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,TResult], T[])
125126
Microsoft.FSharp.Collections.ArrayModule: T Max[T](T[])
@@ -327,6 +328,7 @@ Microsoft.FSharp.Collections.ListModule: T ExactlyOne[T](Microsoft.FSharp.Collec
327328
Microsoft.FSharp.Collections.ListModule: T Find[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean], Microsoft.FSharp.Collections.FSharpList`1[T])
328329
Microsoft.FSharp.Collections.ListModule: T Get[T](Microsoft.FSharp.Collections.FSharpList`1[T], Int32)
329330
Microsoft.FSharp.Collections.ListModule: T Head[T](Microsoft.FSharp.Collections.FSharpList`1[T])
331+
Microsoft.FSharp.Collections.ListModule: T Item[T](Int32, Microsoft.FSharp.Collections.FSharpList`1[T])
330332
Microsoft.FSharp.Collections.ListModule: T Last[T](Microsoft.FSharp.Collections.FSharpList`1[T])
331333
Microsoft.FSharp.Collections.ListModule: T MaxBy[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,TResult], Microsoft.FSharp.Collections.FSharpList`1[T])
332334
Microsoft.FSharp.Collections.ListModule: T Max[T](Microsoft.FSharp.Collections.FSharpList`1[T])
@@ -438,6 +440,7 @@ Microsoft.FSharp.Collections.SeqModule: T ExactlyOne[T](System.Collections.Gener
438440
Microsoft.FSharp.Collections.SeqModule: T Find[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean], System.Collections.Generic.IEnumerable`1[T])
439441
Microsoft.FSharp.Collections.SeqModule: T Get[T](Int32, System.Collections.Generic.IEnumerable`1[T])
440442
Microsoft.FSharp.Collections.SeqModule: T Head[T](System.Collections.Generic.IEnumerable`1[T])
443+
Microsoft.FSharp.Collections.SeqModule: T Item[T](Int32, System.Collections.Generic.IEnumerable`1[T])
441444
Microsoft.FSharp.Collections.SeqModule: T Last[T](System.Collections.Generic.IEnumerable`1[T])
442445
Microsoft.FSharp.Collections.SeqModule: T MaxBy[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,TResult], System.Collections.Generic.IEnumerable`1[T])
443446
Microsoft.FSharp.Collections.SeqModule: T Max[T](System.Collections.Generic.IEnumerable`1[T])

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,9 @@ namespace Microsoft.FSharp.Collections
822822
res.[i]<- array.[startIndex+ i]
823823
res
824824

825+
[<CompiledName("Item")>]
826+
letitem n(array:_[])=
827+
array.[n]
825828

826829
[<CompiledName("Get")>]
827830
letget(array:_[])n=

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,8 @@ namespace Microsoft.FSharp.Collections
332332
///<param name="array">The input array.</param>
333333
///<param name="index">The input index.</param>
334334
///<returns>The value of the array at the given index.</returns>
335+
///<exception cref="System.NullReferenceException">Thrown when the input array is null.</exception>
336+
///<exception cref="System.IndexOutOfRangeException">Thrown when the index is negative or the input array does not contain enough elements.</exception>
335337
[<CompiledName("Get")>]
336338
val get:array:'T[]->index:int-> 'T
337339

@@ -406,6 +408,15 @@ namespace Microsoft.FSharp.Collections
406408
[<CompiledName("Last")>]
407409
val inline last:array:'T[]-> 'T
408410

411+
///<summary>Gets an element from an array.</summary>
412+
///<param name="index">The input index.</param>
413+
///<param name="array">The input array.</param>
414+
///<returns>The value of the array at the given index.</returns>
415+
///<exception cref="System.NullReferenceException">Thrown when the input array is null.</exception>
416+
///<exception cref="System.IndexOutOfRangeException">Thrown when the index is negative or the input array does not contain enough elements.</exception>
417+
[<CompiledName("Item")>]
418+
val item:index:int->array:'T[]-> 'T
419+
409420
///<summary>Returns the length of an array. You can also use property arr.Length.</summary>
410421
///<param name="array">The input array.</param>
411422
///<returns>The length of the array.</returns>
@@ -610,6 +621,8 @@ namespace Microsoft.FSharp.Collections
610621
///<param name="array">The input array.</param>
611622
///<param name="index">The input index.</param>
612623
///<param name="value">The input value.</param>
624+
///<exception cref="System.NullReferenceException">Thrown when the input array is null.</exception>
625+
///<exception cref="System.IndexOutOfRangeException">Thrown when the index is negative or the input array does not contain enough elements.</exception>
613626
[<CompiledName("Set")>]
614627
val set:array:'T[]->index:int->value:'T->unit
615628

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,17 @@ namespace Microsoft.FSharp.Collections
8888
[<CompiledName("Append")>]
8989
letappend list1 list2= list1@ list2
9090

91-
[<CompiledName("Get")>]
92-
let recnth listindex=
93-
match listwith
94-
| h::twhen index>=0->
95-
if index=0then helsenth t(index-1)
96-
|_->
91+
[<CompiledName("Item")>]
92+
let recitemindexlist=
93+
match listwith
94+
| h::twhen index>=0->
95+
if index=0then helseitem(index-1) t
96+
|_->
9797
invalidArg"index"(SR.GetString(SR.indexOutOfBounds))
9898

99+
[<CompiledName("Get")>]
100+
letnth list index= item index list
101+
99102
let recchooseAllAcc f xs acc=
100103
match xswith
101104
|[]-> rev acc

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp