Skip to content

Commit

Permalink
Merge pull request #87 from Karamell/truncate
Browse files Browse the repository at this point in the history
Add truncate as an alias to mimic Seq.
  • Loading branch information
dsyme authored Oct 18, 2018
2 parents 2cfd11f + ad56659 commit 9b608ff
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/FSharp.Control.AsyncSeq/AsyncSeq.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1285,6 +1285,8 @@ module AsyncSeq =
let! moven = ie.MoveNext()
b := moven
else b := None }

let truncate count source = take count source

let skip count (source : AsyncSeq<'T>) : AsyncSeq<_> = asyncSeq {
if (count < 0) then invalidArg "count" "must be non-negative"
Expand Down
4 changes: 4 additions & 0 deletions src/FSharp.Control.AsyncSeq/AsyncSeq.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -397,8 +397,12 @@ module AsyncSeq =
val skipWhile : predicate:('T -> bool) -> source:AsyncSeq<'T> -> AsyncSeq<'T>

/// Returns the first N elements of an asynchronous sequence
/// does not cast an exception if count is larger than the sequence length.
val take : count:int -> source:AsyncSeq<'T> -> AsyncSeq<'T>

/// Alias for take
val truncate : count:int -> source:AsyncSeq<'T> -> AsyncSeq<'T>

/// Skips the first N elements of an asynchronous sequence and
/// then returns the rest of the sequence unmodified.
val skip : count:int -> source:AsyncSeq<'T> -> AsyncSeq<'T>
Expand Down
10 changes: 10 additions & 0 deletions tests/FSharp.Control.AsyncSeq.Tests/AsyncSeqTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1401,6 +1401,16 @@ let ``AsyncSeq.take should work``() =
let ls = ss |> AsyncSeq.toList
()

[<Test>]
let ``AsyncSeq.truncate should work like take``() =
let s = asyncSeq {
yield ["a",1] |> Map.ofList
}
let expected = s |> AsyncSeq.take 1
let actual = s |> AsyncSeq.truncate 1
Assert.AreEqual(expected, actual)


[<Test>]
let ``AsyncSeq.mapAsyncParallel should maintain order`` () =
for i in 0..100 do
Expand Down

0 comments on commit 9b608ff

Please sign in to comment.