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

Commit0e57aa3

Browse files
forkilatkin
authored andcommitted
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
1 parentbefea5b commit0e57aa3

File tree

8 files changed

+40
-0
lines changed

8 files changed

+40
-0
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,6 +1193,13 @@ type ArrayModule() =
11931193
memberthis.Partition()=
11941194
this.PartitionTester Array.partition Array.partition
11951195

1196+
[<Test>]
1197+
memberthis.Singleton()=
1198+
Assert.AreEqual([|null|],Array.singletonnull)
1199+
Assert.AreEqual([|"1"|],Array.singleton"1")
1200+
Assert.AreEqual([|[]|],Array.singleton[])
1201+
Assert.AreEqual([|[||]|],Array.singleton[||])
1202+
11961203
#if FX_NO_TPL_PARALLEL
11971204
#else
11981205
[<Test>]

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,3 +688,10 @@ type ListModule() =
688688
letemptyList:int list=[]
689689
letresultEpt= List.contains4 emptyList
690690
Assert.IsFalse(resultEpt)
691+
692+
[<Test>]
693+
memberthis.Singleton()=
694+
Assert.AreEqual([null],List.singletonnull)
695+
Assert.AreEqual(["1"],List.singleton"1")
696+
Assert.AreEqual([[]],List.singleton[])
697+
Assert.AreEqual([[||]],List.singleton[||])

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ Microsoft.FSharp.Collections.ArrayModule: T[] OfList[T](Microsoft.FSharp.Collect
155155
Microsoft.FSharp.Collections.ArrayModule: T[] OfSeq[T](System.Collections.Generic.IEnumerable`1[T])
156156
Microsoft.FSharp.Collections.ArrayModule: T[] Permute[T](Microsoft.FSharp.Core.FSharpFunc`2[System.Int32,System.Int32], T[])
157157
Microsoft.FSharp.Collections.ArrayModule: T[] Reverse[T](T[])
158+
Microsoft.FSharp.Collections.ArrayModule: T[] Singleton[T](T)
158159
Microsoft.FSharp.Collections.ArrayModule: T[] SortBy[T,TKey](Microsoft.FSharp.Core.FSharpFunc`2[T,TKey], T[])
159160
Microsoft.FSharp.Collections.ArrayModule: T[] SortWith[T](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpFunc`2[T,System.Int32]], T[])
160161
Microsoft.FSharp.Collections.ArrayModule: T[] Sort[T](T[])
@@ -292,6 +293,7 @@ Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList
292293
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])
293294
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] Replicate[T](Int32, T)
294295
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] Reverse[T](Microsoft.FSharp.Collections.FSharpList`1[T])
296+
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] Singleton[T](T)
295297
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])
296298
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])
297299
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
@@ -149,6 +149,7 @@ Microsoft.FSharp.Collections.ArrayModule: T[] OfList[T](Microsoft.FSharp.Collect
149149
Microsoft.FSharp.Collections.ArrayModule: T[] OfSeq[T](System.Collections.Generic.IEnumerable`1[T])
150150
Microsoft.FSharp.Collections.ArrayModule: T[] Permute[T](Microsoft.FSharp.Core.FSharpFunc`2[System.Int32,System.Int32], T[])
151151
Microsoft.FSharp.Collections.ArrayModule: T[] Reverse[T](T[])
152+
Microsoft.FSharp.Collections.ArrayModule: T[] Singleton[T](T)
152153
Microsoft.FSharp.Collections.ArrayModule: T[] SortBy[T,TKey](Microsoft.FSharp.Core.FSharpFunc`2[T,TKey], T[])
153154
Microsoft.FSharp.Collections.ArrayModule: T[] SortWith[T](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpFunc`2[T,System.Int32]], T[])
154155
Microsoft.FSharp.Collections.ArrayModule: T[] Sort[T](T[])
@@ -286,6 +287,7 @@ Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList
286287
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])
287288
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] Replicate[T](Int32, T)
288289
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] Reverse[T](Microsoft.FSharp.Collections.FSharpList`1[T])
290+
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] Singleton[T](T)
289291
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])
290292
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])
291293
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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,9 @@ namespace Microsoft.FSharp.Collections
470470
letlen= array.Length
471471
scanSubRight f array0(len-1) acc
472472

473+
[<CompiledName("Singleton")>]
474+
let inlinesingleton value=[|value|]
475+
473476
[<CompiledName("Reduce")>]
474477
letreduce f(array:_[])=
475478
checkNonNull"array" array

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,14 @@ namespace Microsoft.FSharp.Collections
500500
[<CompiledName("ScanBack")>]
501501
val scanBack<'T,'State>:folder:('T-> 'State-> 'State)->array:'T[]->state:'State-> 'State[]
502502

503+
///<summary>Returns an array that contains one item only.</summary>
504+
///
505+
///<param name="value">The input item.</param>
506+
///
507+
///<returns>The result array of one item.</returns>
508+
[<CompiledName("Singleton")>]
509+
val inline singleton:value:'T-> 'T[]
510+
503511
///<summary>Sets an element of an array.</summary>
504512
///<param name="array">The input array.</param>
505513
///<param name="index">The input index.</param>

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@ namespace Microsoft.FSharp.Collections
160160
|(h::t)->lets= f.Invoke(s,h)in loop s t(s:: acc)
161161
loop s list[s]
162162

163+
[<CompiledName("Singleton")>]
164+
let inlinesingleton value=[value]
165+
163166
[<CompiledName("Fold2")>]
164167
letfold2<'T1,'T2,'State>f(acc:'State)(list1:list<'T1>)(list2:list<'T2>)=
165168
letf= OptimizedClosures.FSharpFunc<_,_,_,_>.Adapt(f)

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,14 @@ namespace Microsoft.FSharp.Collections
475475
[<CompiledName("ScanBack")>]
476476
val scanBack<'T,'State>:folder:('T-> 'State-> 'State)->list:'T list->state:'State-> 'State list
477477

478+
///<summary>Returns a list that contains one item only.</summary>
479+
///
480+
///<param name="value">The input item.</param>
481+
///
482+
///<returns>The result list of one item.</returns>
483+
[<CompiledName("Singleton")>]
484+
val inline singleton:value:'T-> 'T list
485+
478486
///<summary>Sorts the given list using the given comparison function.</summary>
479487
///
480488
///<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