@@ -10,67 +10,108 @@ open FSharp.Control
10
10
//
11
11
// TaskSeq.filter
12
12
// TaskSeq.filterAsync
13
+ // TaskSeq.where
14
+ // TaskSeq.whereAsync
13
15
//
14
16
15
17
16
18
module EmptySeq =
17
19
[<Fact>]
18
- let ``Null source is invalid `` () =
20
+ let ``TaskSeq - filter or where with null source raises `` () =
19
21
assertNullArg
20
22
<| fun () -> TaskSeq.filter ( fun _ -> false ) null
21
23
22
24
assertNullArg
23
25
<| fun () -> TaskSeq.filterAsync ( fun _ -> Task.fromResult false ) null
24
26
27
+ assertNullArg
28
+ <| fun () -> TaskSeq.where ( fun _ -> false ) null
29
+
30
+ assertNullArg
31
+ <| fun () -> TaskSeq.whereAsync ( fun _ -> Task.fromResult false ) null
32
+
25
33
26
34
[<Theory; ClassData( typeof< TestEmptyVariants>) >]
27
- let ``TaskSeq - filter has no effect`` variant =
28
- Gen.getEmptyVariant variant
29
- |> TaskSeq.filter ((=) 12 )
30
- |> TaskSeq.toListAsync
31
- |> Task.map ( List.isEmpty >> should be True)
35
+ let ``TaskSeq - filter or where has no effect`` variant = task {
36
+ do !
37
+ Gen.getEmptyVariant variant
38
+ |> TaskSeq.filter ((=) 12 )
39
+ |> TaskSeq.toListAsync
40
+ |> Task.map ( List.isEmpty >> should be True)
41
+
42
+ do !
43
+ Gen.getEmptyVariant variant
44
+ |> TaskSeq.where ((=) 12 )
45
+ |> TaskSeq.toListAsync
46
+ |> Task.map ( List.isEmpty >> should be True)
47
+ }
32
48
33
49
[<Theory; ClassData( typeof< TestEmptyVariants>) >]
34
- let ``TaskSeq - filterAsync has no effect`` variant =
35
- Gen.getEmptyVariant variant
36
- |> TaskSeq.filterAsync ( fun x -> task { return x = 12 })
37
- |> TaskSeq.toListAsync
38
- |> Task.map ( List.isEmpty >> should be True)
50
+ let ``TaskSeq - filterAsync or whereAsync has no effect`` variant = task {
51
+ do !
52
+ Gen.getEmptyVariant variant
53
+ |> TaskSeq.filterAsync ( fun x -> task { return x = 12 })
54
+ |> TaskSeq.toListAsync
55
+ |> Task.map ( List.isEmpty >> should be True)
56
+
57
+ do !
58
+ Gen.getEmptyVariant variant
59
+ |> TaskSeq.whereAsync ( fun x -> task { return x = 12 })
60
+ |> TaskSeq.toListAsync
61
+ |> Task.map ( List.isEmpty >> should be True)
62
+ }
39
63
40
64
module Immutable =
41
65
[<Theory; ClassData( typeof< TestImmTaskSeq>) >]
42
- let ``TaskSeq - filter filters correctly`` variant =
43
- Gen.getSeqImmutable variant
44
- |> TaskSeq.filter ((<=) 5 ) // greater than
45
- |> TaskSeq.map char
46
- |> TaskSeq.map ((+) '@' )
47
- |> TaskSeq.toArrayAsync
48
- |> Task.map ( String >> should equal " EFGHIJ" )
66
+ let ``TaskSeq - filter or where filters correctly`` variant = task {
67
+ do !
68
+ Gen.getSeqImmutable variant
69
+ |> TaskSeq.filter ((<=) 5 ) // greater than
70
+ |> verifyDigitsAsString " EFGHIJ"
71
+
72
+ do !
73
+ Gen.getSeqImmutable variant
74
+ |> TaskSeq.where ((>) 5 ) // greater than
75
+ |> verifyDigitsAsString " ABCD"
76
+ }
49
77
50
78
[<Theory; ClassData( typeof< TestImmTaskSeq>) >]
51
- let ``TaskSeq - filterAsync filters correctly`` variant =
52
- Gen.getSeqImmutable variant
53
- |> TaskSeq.filterAsync ( fun x -> task { return x <= 5 })
54
- |> TaskSeq.map char
55
- |> TaskSeq.map ((+) '@' )
56
- |> TaskSeq.toArrayAsync
57
- |> Task.map ( String >> should equal " ABCDE" )
79
+ let ``TaskSeq - filterAsync or whereAsync filters correctly`` variant = task {
80
+ do !
81
+ Gen.getSeqImmutable variant
82
+ |> TaskSeq.filterAsync ( fun x -> task { return x <= 5 })
83
+ |> verifyDigitsAsString " ABCDE"
84
+
85
+ do !
86
+ Gen.getSeqImmutable variant
87
+ |> TaskSeq.whereAsync ( fun x -> task { return x > 5 })
88
+ |> verifyDigitsAsString " FGHIJ"
89
+
90
+ }
58
91
59
92
module SideEffects =
60
93
[<Theory; ClassData( typeof< TestSideEffectTaskSeq>) >]
61
- let ``TaskSeq - filter filters correctly`` variant =
62
- Gen.getSeqWithSideEffect variant
63
- |> TaskSeq.filter ((<=) 5 ) // greater than
64
- |> TaskSeq.map char
65
- |> TaskSeq.map ((+) '@' )
66
- |> TaskSeq.toArrayAsync
67
- |> Task.map ( String >> should equal " EFGHIJ" )
94
+ let ``TaskSeq - filter filters correctly`` variant = task {
95
+ do !
96
+ Gen.getSeqWithSideEffect variant
97
+ |> TaskSeq.filter ((<=) 5 ) // greater than or equal
98
+ |> verifyDigitsAsString " EFGHIJ"
99
+
100
+ do !
101
+ Gen.getSeqWithSideEffect variant
102
+ |> TaskSeq.where ((>) 5 ) // less than
103
+ |> verifyDigitsAsString " ABCD"
104
+ }
68
105
69
106
[<Theory; ClassData( typeof< TestSideEffectTaskSeq>) >]
70
- let ``TaskSeq - filterAsync filters correctly`` variant =
71
- Gen.getSeqWithSideEffect variant
72
- |> TaskSeq.filterAsync ( fun x -> task { return x <= 5 })
73
- |> TaskSeq.map char
74
- |> TaskSeq.map ((+) '@' )
75
- |> TaskSeq.toArrayAsync
76
- |> Task.map ( String >> should equal " ABCDE" )
107
+ let ``TaskSeq - filterAsync filters correctly`` variant = task {
108
+ do !
109
+ Gen.getSeqWithSideEffect variant
110
+ |> TaskSeq.filterAsync ( fun x -> task { return x <= 5 })
111
+ |> verifyDigitsAsString " ABCDE"
112
+
113
+ do !
114
+ Gen.getSeqWithSideEffect variant
115
+ |> TaskSeq.whereAsync ( fun x -> task { return x > 5 && x < 9 })
116
+ |> verifyDigitsAsString " FGH"
117
+ }
0 commit comments