提交 f197816d 编写于 作者: S Steffen Forkmann 提交者: latkin

Implement Array.head

commit 5898cc7e82befdbf9b7457f41e898c3b1b916a57
Merge: 173d8336 fec1862
Author: latkin <latkin@microsoft.com>
Date:   Sun Oct 12 10:15:38 2014 -0700

    Merge branch 'hd' of https://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.fs

commit fec186272559585de8e47fe070189751906f8553
Author: Steffen Forkmann <steffen.forkmann@msu-solutions.de>
Date:   Wed Jul 2 18:29:27 2014 +0200

    Adding surface areay for Array.head

commit 334166c0ada7d5457f3c77756d192167b5ebf9f1
Author: Steffen Forkmann <steffen.forkmann@msu-solutions.de>
Date:   Wed Jul 2 18:25:36 2014 +0200

    Improve docs for Array.head

commit 9dd524476c8afe127d64d2d2d87ae81cae736737
Author: Steffen Forkmann <steffen.forkmann@msu-solutions.de>
Date:   Wed Jul 2 18:24:40 2014 +0200

    Fixing error message for Array.head

commit b4cf72e2b22b574c28fb7daaf85887546dd06b17
Author: Steffen Forkmann <steffen.forkmann@msu-solutions.de>
Date:   Mon Jun 30 15:56:22 2014 +0200

    implementing "head" for array
上级 173d8336
......@@ -962,6 +962,20 @@ type ArrayModule() =
()
[<Test>]
member this.Hd() =
// integer array
let resultInt = Array.head [|2..2..20|]
Assert.AreEqual(2, resultInt)
// string array
let resultStr = Array.head [|"a";"b";"c";"d"|]
Assert.AreEqual("a", resultStr)
CheckThrowsArgumentException(fun () -> Array.head [||] |> ignore)
CheckThrowsArgumentNullException(fun () -> Array.head null |> ignore)
()
[<Test>]
member this.Init() =
this.InitTester Array.init Array.init
......
......@@ -124,6 +124,7 @@ Microsoft.FSharp.Collections.ArrayModule: T Average[T](T[])
Microsoft.FSharp.Collections.ArrayModule: T ExactlyOne[T](T[])
Microsoft.FSharp.Collections.ArrayModule: T Find[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean], T[])
Microsoft.FSharp.Collections.ArrayModule: T Get[T](T[], Int32)
Microsoft.FSharp.Collections.ArrayModule: T Head[T](T[])
Microsoft.FSharp.Collections.ArrayModule: T Last[T](T[])
Microsoft.FSharp.Collections.ArrayModule: T MaxBy[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,TResult], T[])
Microsoft.FSharp.Collections.ArrayModule: T Max[T](T[])
......
......@@ -118,6 +118,7 @@ Microsoft.FSharp.Collections.ArrayModule: T Average[T](T[])
Microsoft.FSharp.Collections.ArrayModule: T ExactlyOne[T](T[])
Microsoft.FSharp.Collections.ArrayModule: T Find[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean], T[])
Microsoft.FSharp.Collections.ArrayModule: T Get[T](T[], Int32)
Microsoft.FSharp.Collections.ArrayModule: T Head[T](T[])
Microsoft.FSharp.Collections.ArrayModule: T Last[T](T[])
Microsoft.FSharp.Collections.ArrayModule: T MaxBy[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,TResult], T[])
Microsoft.FSharp.Collections.ArrayModule: T Max[T](T[])
......
......@@ -177,7 +177,12 @@ namespace Microsoft.FSharp.Collections
let res : 'T[] = Microsoft.FSharp.Primitives.Basics.Array.zeroCreateUnchecked (n1 + n2)
Array.Copy(array1, 0, res, 0, n1)
Array.Copy(array2, 0, res, n1, n2)
res
res
[<CompiledName("Head")>]
let head (array : 'T[]) =
checkNonNull "array" array
if array.Length = 0 then invalidArg "array" InputArrayEmptyString else array.[0]
[<CompiledName("Copy")>]
let copy (array: 'T[]) =
......
......@@ -322,6 +322,17 @@ namespace Microsoft.FSharp.Collections
[<CompiledName("Get")>]
val get: array:'T[] -> index:int -> 'T
/// <summary>Returns the first element of the array.</summary>
///
/// <param name="array">The input array.</param>
///
/// <returns>The first element of the array.</returns>
///
/// <exception cref="System.ArgumentNullException">Thrown when the input array is null.</exception>
/// <exception cref="System.ArgumentException">Thrown when the input array is empty.</exception>
[<CompiledName("Head")>]
val head: array:'T[] -> 'T
/// <summary>Creates an array given the dimension and a generator function to compute the elements.</summary>
/// <param name="count">The number of elements to initialize.</param>
/// <param name="initializer">The function to generate the initial values for each index.</param>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册