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

Commitf197816

Browse files
forkilatkin
authored andcommitted
Implement Array.head
commit 5898cc7e82befdbf9b7457f41e898c3b1b916a57Merge:173d833 fec1862Author: latkin <latkin@microsoft.com>Date: Sun Oct 12 10:15:38 2014 -0700 Merge branch 'hd' ofhttps://git01.codeplex.com/forks/forki/fsharp into PR Conflicts: src/fsharp/FSharp.Core.Unittests/SurfaceArea.4.0.fs src/fsharp/FSharp.Core.Unittests/SurfaceArea.Portable.fscommit fec186272559585de8e47fe070189751906f8553Author: Steffen Forkmann <steffen.forkmann@msu-solutions.de>Date: Wed Jul 2 18:29:27 2014 +0200 Adding surface areay for Array.headcommit 334166c0ada7d5457f3c77756d192167b5ebf9f1Author: Steffen Forkmann <steffen.forkmann@msu-solutions.de>Date: Wed Jul 2 18:25:36 2014 +0200 Improve docs for Array.headcommit 9dd524476c8afe127d64d2d2d87ae81cae736737Author: Steffen Forkmann <steffen.forkmann@msu-solutions.de>Date: Wed Jul 2 18:24:40 2014 +0200 Fixing error message for Array.headcommit b4cf72e2b22b574c28fb7daaf85887546dd06b17Author: Steffen Forkmann <steffen.forkmann@msu-solutions.de>Date: Mon Jun 30 15:56:22 2014 +0200 implementing "head" for array
1 parent173d833 commitf197816

File tree

5 files changed

+33
-1
lines changed

5 files changed

+33
-1
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -962,6 +962,20 @@ type ArrayModule() =
962962

963963
()
964964

965+
[<Test>]
966+
memberthis.Hd()=
967+
// integer array
968+
letresultInt= Array.head[|2..2..20|]
969+
Assert.AreEqual(2, resultInt)
970+
971+
// string array
972+
letresultStr= Array.head[|"a";"b";"c";"d"|]
973+
Assert.AreEqual("a", resultStr)
974+
975+
CheckThrowsArgumentException(fun()-> Array.head[||]|> ignore)
976+
CheckThrowsArgumentNullException(fun()-> Array.headnull|> ignore)
977+
()
978+
965979
[<Test>]
966980
memberthis.Init()=
967981
this.InitTester Array.init Array.init

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ Microsoft.FSharp.Collections.ArrayModule: T Average[T](T[])
124124
Microsoft.FSharp.Collections.ArrayModule: T ExactlyOne[T](T[])
125125
Microsoft.FSharp.Collections.ArrayModule: T Find[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean], T[])
126126
Microsoft.FSharp.Collections.ArrayModule: T Get[T](T[], Int32)
127+
Microsoft.FSharp.Collections.ArrayModule: T Head[T](T[])
127128
Microsoft.FSharp.Collections.ArrayModule: T Last[T](T[])
128129
Microsoft.FSharp.Collections.ArrayModule: T MaxBy[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,TResult], T[])
129130
Microsoft.FSharp.Collections.ArrayModule: T Max[T](T[])

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ Microsoft.FSharp.Collections.ArrayModule: T Average[T](T[])
118118
Microsoft.FSharp.Collections.ArrayModule: T ExactlyOne[T](T[])
119119
Microsoft.FSharp.Collections.ArrayModule: T Find[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean], T[])
120120
Microsoft.FSharp.Collections.ArrayModule: T Get[T](T[], Int32)
121+
Microsoft.FSharp.Collections.ArrayModule: T Head[T](T[])
121122
Microsoft.FSharp.Collections.ArrayModule: T Last[T](T[])
122123
Microsoft.FSharp.Collections.ArrayModule: T MaxBy[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,TResult], T[])
123124
Microsoft.FSharp.Collections.ArrayModule: T Max[T](T[])

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,12 @@ namespace Microsoft.FSharp.Collections
177177
letres:'T[]= Microsoft.FSharp.Primitives.Basics.Array.zeroCreateUnchecked(n1+ n2)
178178
Array.Copy(array1,0, res,0, n1)
179179
Array.Copy(array2,0, res, n1, n2)
180-
res
180+
res
181+
182+
[<CompiledName("Head")>]
183+
lethead(array:'T[])=
184+
checkNonNull"array" array
185+
if array.Length=0then invalidArg"array" InputArrayEmptyStringelse array.[0]
181186

182187
[<CompiledName("Copy")>]
183188
letcopy(array:'T[])=

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,17 @@ namespace Microsoft.FSharp.Collections
322322
[<CompiledName("Get")>]
323323
val get:array:'T[]->index:int-> 'T
324324

325+
///<summary>Returns the first element of the array.</summary>
326+
///
327+
///<param name="array">The input array.</param>
328+
///
329+
///<returns>The first element of the array.</returns>
330+
///
331+
///<exception cref="System.ArgumentNullException">Thrown when the input array is null.</exception>
332+
///<exception cref="System.ArgumentException">Thrown when the input array is empty.</exception>
333+
[<CompiledName("Head")>]
334+
val head:array:'T[]-> 'T
335+
325336
///<summary>Creates an array given the dimension and a generator function to compute the elements.</summary>
326337
///<param name="count">The number of elements to initialize.</param>
327338
///<param name="initializer">The function to generate the initial values for each index.</param>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp