-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathTaskSeq.Delay.Tests.fs
More file actions
50 lines (41 loc) · 1.17 KB
/
TaskSeq.Delay.Tests.fs
File metadata and controls
50 lines (41 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
module TaskSeq.Tests.Delay
open Xunit
open FsUnit.Xunit
open FSharp.Control
//
// TaskSeq.delay
//
let validateSequence ts =
ts
|> TaskSeq.toListAsync
|> Task.map (List.map string)
|> Task.map (String.concat "")
|> Task.map (should equal "12345678910")
module EmptySeq =
[<Theory; ClassData(typeof<TestEmptyVariants>)>]
let ``TaskSeq-delay with empty sequences`` variant =
fun () -> Gen.getEmptyVariant variant
|> TaskSeq.delay
|> verifyEmpty
module Immutable =
[<Theory; ClassData(typeof<TestImmTaskSeq>)>]
let ``TaskSeq-delay`` variant =
fun () -> Gen.getSeqImmutable variant
|> TaskSeq.delay
|> validateSequence
module SideEffect =
[<Fact>]
let ``TaskSeq-delay executes side effects`` () = task {
let mutable i = 0
let ts =
fun () -> taskSeq {
yield! [ 1..10 ]
i <- i + 1
}
|> TaskSeq.delay
do! ts |> validateSequence
i |> should equal 1
let! len = TaskSeq.length ts
i |> should equal 2 // re-eval of the sequence executes side effect again
len |> should equal 10
}