-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add TaskSeq.fold and TaskSeq.foldAsync functions and tests
- Loading branch information
1 parent
8b34b9d
commit 4b78f79
Showing
4 changed files
with
79 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
module FSharpy.TaskSeq.Tests.Fold | ||
|
||
open System.Text | ||
open Xunit | ||
open FsUnit.Xunit | ||
open FsToolkit.ErrorHandling | ||
|
||
open FSharpy | ||
|
||
|
||
[<Fact>] | ||
let ``TaskSeq-fold folds with every item`` () = task { | ||
let! alphabet = | ||
createDummyTaskSeqWith 50L<µs> 1000L<µs> 26 | ||
|> TaskSeq.fold (fun (state: StringBuilder) item -> state.Append(char item + '@')) (StringBuilder()) | ||
|
||
alphabet.ToString() | ||
|> should equal "ABCDEFGHIJKLMNOPQRSTUVWXYZ" | ||
} | ||
|
||
[<Fact>] | ||
let ``TaskSeq-foldAsync folds with every item`` () = task { | ||
let! alphabet = | ||
createDummyTaskSeqWith 50L<µs> 1000L<µs> 26 | ||
|> TaskSeq.foldAsync | ||
(fun (state: StringBuilder) item -> task { return state.Append(char item + '@') }) | ||
(StringBuilder()) | ||
|
||
alphabet.ToString() | ||
|> should equal "ABCDEFGHIJKLMNOPQRSTUVWXYZ" | ||
} | ||
|
||
[<Fact>] | ||
let ``TaskSeq-fold takes state on empty IAsyncEnumberable`` () = task { | ||
let! empty = | ||
TaskSeq.empty | ||
|> TaskSeq.fold (fun _ item -> char (item + 64)) '_' | ||
|
||
empty |> should equal '_' | ||
} | ||
|
||
[<Fact>] | ||
let ``TaskSeq-foldAsync takes state on empty IAsyncEnumerable`` () = task { | ||
let! alphabet = | ||
TaskSeq.empty | ||
|> TaskSeq.foldAsync (fun _ item -> task { return char (item + 64) }) '_' | ||
|
||
alphabet |> should equal '_' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters