Skip to content

Commit 9b608ff

Browse files
authored
Merge pull request #87 from Karamell/truncate
Add truncate as an alias to mimic Seq.
2 parents 2cfd11f + ad56659 commit 9b608ff

3 files changed

Lines changed: 16 additions & 0 deletions

File tree

src/FSharp.Control.AsyncSeq/AsyncSeq.fs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,6 +1285,8 @@ module AsyncSeq =
12851285
let! moven = ie.MoveNext()
12861286
b := moven
12871287
else b := None }
1288+
1289+
let truncate count source = take count source
12881290

12891291
let skip count (source : AsyncSeq<'T>) : AsyncSeq<_> = asyncSeq {
12901292
if (count < 0) then invalidArg "count" "must be non-negative"

src/FSharp.Control.AsyncSeq/AsyncSeq.fsi

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,8 +397,12 @@ module AsyncSeq =
397397
val skipWhile : predicate:('T -> bool) -> source:AsyncSeq<'T> -> AsyncSeq<'T>
398398

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

403+
/// Alias for take
404+
val truncate : count:int -> source:AsyncSeq<'T> -> AsyncSeq<'T>
405+
402406
/// Skips the first N elements of an asynchronous sequence and
403407
/// then returns the rest of the sequence unmodified.
404408
val skip : count:int -> source:AsyncSeq<'T> -> AsyncSeq<'T>

tests/FSharp.Control.AsyncSeq.Tests/AsyncSeqTests.fs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1401,6 +1401,16 @@ let ``AsyncSeq.take should work``() =
14011401
let ls = ss |> AsyncSeq.toList
14021402
()
14031403

1404+
[<Test>]
1405+
let ``AsyncSeq.truncate should work like take``() =
1406+
let s = asyncSeq {
1407+
yield ["a",1] |> Map.ofList
1408+
}
1409+
let expected = s |> AsyncSeq.take 1
1410+
let actual = s |> AsyncSeq.truncate 1
1411+
Assert.AreEqual(expected, actual)
1412+
1413+
14041414
[<Test>]
14051415
let ``AsyncSeq.mapAsyncParallel should maintain order`` () =
14061416
for i in 0..100 do

0 commit comments

Comments
 (0)