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

Commitda29df5

Browse files
PatrickMcDonaldlatkin
authored andcommitted
Implement Seq.rev
commit 86e426c1e8ec90ab465b97e3d6fc20f33298ab44Merge: 9ab414a dd2fb17Author: latkin <latkin@microsoft.com>Date: Tue Oct 21 15:43:10 2014 -0700 Merge branch 'rev' ofhttps://git01.codeplex.com/forks/patrickmcdonald/visualfsharp into PR Conflicts: src/fsharp/FSharp.Core.Unittests/FSharp.Core/Microsoft.FSharp.Collections/SeqModule2.fs src/fsharp/FSharp.Core.Unittests/SurfaceArea.4.0.fs src/fsharp/FSharp.Core.Unittests/SurfaceArea.Portable.fs src/fsharp/FSharp.Core/seq.fsicommit dd2fb1787597e89ccff82c1808b555177b928a11Author: Patrick McDonald <paddymcdonald@gmail.com>Date: Wed Aug 27 23:33:15 2014 +0100 Implement Seq.rev
1 parent366777f commitda29df5

File tree

5 files changed

+35
-0
lines changed

5 files changed

+35
-0
lines changed

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -947,6 +947,24 @@ type SeqModule2() =
947947

948948
()
949949

950+
[<Test>]
951+
memberthis.Rev()=
952+
// integer Seq
953+
letresultInt= Seq.rev(seq[5;4;3;2;1])
954+
VerifySeqsEqual(seq[1;2;3;4;5]) resultInt
955+
956+
// string Seq
957+
letresultStr= Seq.rev(seq["A";"B";"C";"D"])
958+
VerifySeqsEqual(seq["D";"C";"B";"A"]) resultStr
959+
960+
// empty Seq
961+
VerifySeqsEqual Seq.empty(Seq.rev Seq.empty)
962+
963+
// null Seq
964+
letnullSeq:seq<'a>=null
965+
CheckThrowsArgumentNullException(fun()-> Seq.rev nullSeq|> ignore)
966+
()
967+
950968
[<Test>]
951969
memberthis.Scan()=
952970
// integer Seq

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,7 @@ Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1
436436
Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T] OfList[T](Microsoft.FSharp.Collections.FSharpList`1[T])
437437
Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T] ReadOnly[T](System.Collections.Generic.IEnumerable`1[T])
438438
Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T] Replicate[T](Int32, T)
439+
Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T] Reverse[T](System.Collections.Generic.IEnumerable`1[T])
439440
Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T] Singleton[T](T)
440441
Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T] SkipWhile[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean], System.Collections.Generic.IEnumerable`1[T])
441442
Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T] Skip[T](Int32, System.Collections.Generic.IEnumerable`1[T])

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,7 @@ Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1
430430
Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T] OfList[T](Microsoft.FSharp.Collections.FSharpList`1[T])
431431
Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T] ReadOnly[T](System.Collections.Generic.IEnumerable`1[T])
432432
Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T] Replicate[T](Int32, T)
433+
Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T] Reverse[T](System.Collections.Generic.IEnumerable`1[T])
433434
Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T] Singleton[T](T)
434435
Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T] SkipWhile[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean], System.Collections.Generic.IEnumerable`1[T])
435436
Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T] Skip[T](Int32, System.Collections.Generic.IEnumerable`1[T])

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1704,3 +1704,11 @@ namespace Microsoft.FSharp.Collections
17041704
v
17051705
else
17061706
invalidArg"source" InputSequenceEmptyString
1707+
1708+
[<CompiledName("Reverse")>]
1709+
letrev source=
1710+
checkNonNull"source" source
1711+
mkDelayedSeq(fun()->
1712+
letarray= source|> toArray
1713+
Array.Reverse array
1714+
array:> seq<_>)

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,13 @@ namespace Microsoft.FSharp.Collections
818818
[<CompiledName("ReduceBack")>]
819819
val reduceBack:reduction:('T-> 'T-> 'T)->source:seq<'T>-> 'T
820820

821+
///<summary>Returns a new sequence with the elements in reverse order.</summary>
822+
///<param name="source">The input sequence.</param>
823+
///<returns>The reversed sequence.</returns>
824+
///<exception cref="System.ArgumentNullException">Thrown when the input sequence is null.</exception>
825+
[<CompiledName("Reverse")>]
826+
val rev:source:seq<'T>->seq<'T>
827+
821828
///<summary>Like fold,but computes on-demand and returns the sequence of intermediary and final results.</summary>
822829
///
823830
///<param name="folder">A function that updates the state with each element from the sequence.</param>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp