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

Implement Array.singleton, List.singleton

Commits:
    implementing "singleton" for array and list

    Add surface area for singleton

    Add null test case for singleton

    Change 'yields' to 'contains' in docs, per code review
上级 befea5b6
......@@ -1193,6 +1193,13 @@ type ArrayModule() =
member this.Partition () =
this.PartitionTester Array.partition Array.partition
[<Test>]
member this.Singleton() =
Assert.AreEqual([|null|],Array.singleton null)
Assert.AreEqual([|"1"|],Array.singleton "1")
Assert.AreEqual([|[]|],Array.singleton [])
Assert.AreEqual([|[||]|],Array.singleton [||])
#if FX_NO_TPL_PARALLEL
#else
[<Test>]
......
......@@ -688,3 +688,10 @@ type ListModule() =
let emptyList:int list = [ ]
let resultEpt = List.contains 4 emptyList
Assert.IsFalse(resultEpt)
[<Test>]
member this.Singleton() =
Assert.AreEqual([null],List.singleton null)
Assert.AreEqual(["1"],List.singleton "1")
Assert.AreEqual([[]],List.singleton [])
Assert.AreEqual([[||]],List.singleton [||])
\ No newline at end of file
......@@ -155,6 +155,7 @@ Microsoft.FSharp.Collections.ArrayModule: T[] OfList[T](Microsoft.FSharp.Collect
Microsoft.FSharp.Collections.ArrayModule: T[] OfSeq[T](System.Collections.Generic.IEnumerable`1[T])
Microsoft.FSharp.Collections.ArrayModule: T[] Permute[T](Microsoft.FSharp.Core.FSharpFunc`2[System.Int32,System.Int32], T[])
Microsoft.FSharp.Collections.ArrayModule: T[] Reverse[T](T[])
Microsoft.FSharp.Collections.ArrayModule: T[] Singleton[T](T)
Microsoft.FSharp.Collections.ArrayModule: T[] SortBy[T,TKey](Microsoft.FSharp.Core.FSharpFunc`2[T,TKey], T[])
Microsoft.FSharp.Collections.ArrayModule: T[] SortWith[T](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpFunc`2[T,System.Int32]], T[])
Microsoft.FSharp.Collections.ArrayModule: T[] Sort[T](T[])
......@@ -292,6 +293,7 @@ Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] Permute[T](Microsoft.FSharp.Core.FSharpFunc`2[System.Int32,System.Int32], Microsoft.FSharp.Collections.FSharpList`1[T])
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] Replicate[T](Int32, T)
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] Reverse[T](Microsoft.FSharp.Collections.FSharpList`1[T])
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] Singleton[T](T)
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])
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])
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] Sort[T](Microsoft.FSharp.Collections.FSharpList`1[T])
......
......@@ -149,6 +149,7 @@ Microsoft.FSharp.Collections.ArrayModule: T[] OfList[T](Microsoft.FSharp.Collect
Microsoft.FSharp.Collections.ArrayModule: T[] OfSeq[T](System.Collections.Generic.IEnumerable`1[T])
Microsoft.FSharp.Collections.ArrayModule: T[] Permute[T](Microsoft.FSharp.Core.FSharpFunc`2[System.Int32,System.Int32], T[])
Microsoft.FSharp.Collections.ArrayModule: T[] Reverse[T](T[])
Microsoft.FSharp.Collections.ArrayModule: T[] Singleton[T](T)
Microsoft.FSharp.Collections.ArrayModule: T[] SortBy[T,TKey](Microsoft.FSharp.Core.FSharpFunc`2[T,TKey], T[])
Microsoft.FSharp.Collections.ArrayModule: T[] SortWith[T](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpFunc`2[T,System.Int32]], T[])
Microsoft.FSharp.Collections.ArrayModule: T[] Sort[T](T[])
......@@ -286,6 +287,7 @@ Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] Permute[T](Microsoft.FSharp.Core.FSharpFunc`2[System.Int32,System.Int32], Microsoft.FSharp.Collections.FSharpList`1[T])
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] Replicate[T](Int32, T)
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] Reverse[T](Microsoft.FSharp.Collections.FSharpList`1[T])
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] Singleton[T](T)
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])
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])
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] Sort[T](Microsoft.FSharp.Collections.FSharpList`1[T])
......
......@@ -470,6 +470,9 @@ namespace Microsoft.FSharp.Collections
let len = array.Length
scanSubRight f array 0 (len - 1) acc
[<CompiledName("Singleton")>]
let inline singleton value = [|value|]
[<CompiledName("Reduce")>]
let reduce f (array : _[]) =
checkNonNull "array" array
......
......@@ -500,6 +500,14 @@ namespace Microsoft.FSharp.Collections
[<CompiledName("ScanBack")>]
val scanBack<'T,'State> : folder:('T -> 'State -> 'State) -> array:'T[] -> state:'State -> 'State[]
/// <summary>Returns an array that contains one item only.</summary>
///
/// <param name="value">The input item.</param>
///
/// <returns>The result array of one item.</returns>
[<CompiledName("Singleton")>]
val inline singleton: value:'T -> 'T[]
/// <summary>Sets an element of an array.</summary>
/// <param name="array">The input array.</param>
/// <param name="index">The input index.</param>
......
......@@ -160,6 +160,9 @@ namespace Microsoft.FSharp.Collections
| (h::t) -> let s = f.Invoke(s,h) in loop s t (s :: acc)
loop s list [s]
[<CompiledName("Singleton")>]
let inline singleton value = [value]
[<CompiledName("Fold2")>]
let fold2<'T1,'T2,'State> f (acc:'State) (list1:list<'T1>) (list2:list<'T2>) =
let f = OptimizedClosures.FSharpFunc<_,_,_,_>.Adapt(f)
......
......@@ -475,6 +475,14 @@ namespace Microsoft.FSharp.Collections
[<CompiledName("ScanBack")>]
val scanBack<'T,'State> : folder:('T -> 'State -> 'State) -> list:'T list -> state:'State -> 'State list
/// <summary>Returns a list that contains one item only.</summary>
///
/// <param name="value">The input item.</param>
///
/// <returns>The result list of one item.</returns>
[<CompiledName("Singleton")>]
val inline singleton: value:'T -> 'T list
/// <summary>Sorts the given list using the given comparison function.</summary>
///
/// <remarks>This is a stable sort, i.e. the original order of equal elements is preserved.</remarks>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册