@@ -18,16 +18,6 @@ module TaskOptionCE =
18
18
: Ply < Option < _ >> =
19
19
uply.ReturnFrom taskResult
20
20
21
- member inline this.ReturnFrom
22
- ( asyncResult : Async < Option < _ >>)
23
- : Ply < Option < _ >> =
24
- this.ReturnFrom ( Async.StartAsTask asyncResult)
25
-
26
- member inline _.ReturnFrom
27
- ( result : Option < _ >)
28
- : Ply < Option < _ >> =
29
- uply.Return result
30
-
31
21
member inline _.Zero () : Ply < Option < _ >> =
32
22
uply.Return <| option.Zero()
33
23
@@ -40,20 +30,6 @@ module TaskOptionCE =
40
30
| Some x -> binder x
41
31
| None -> uply.Return None
42
32
uply.Bind( taskResult, binder')
43
-
44
- member inline this.Bind
45
- ( asyncResult : Async < Option < _ >>,
46
- binder : 'T -> Ply < Option < _ >>)
47
- : Ply < Option < _ >> =
48
- this.Bind( Async.StartAsTask asyncResult, binder)
49
-
50
- member inline this.Bind
51
- ( result : Option < _ >, binder : 'T -> Ply < Option < _ >>)
52
- : Ply < Option < _ >> =
53
- let result =
54
- result
55
- |> Task.singleton
56
- this.Bind( result, binder)
57
33
58
34
member inline _.Delay
59
35
( generator : unit -> Ply < Option < _ >>) =
@@ -117,4 +93,40 @@ module TaskOptionCE =
117
93
118
94
member inline _.Run ( f : unit -> Ply < 'm >) = task.Run f
119
95
96
+ /// <summary>
97
+ /// Method lets us transform data types into our internal representation. This is the identity method to recognize the self type.
98
+ /// See https://stackoverflow.com/questions/35286541/why-would-you-use-builder-source-in-a-custom-computation-expression-builder
99
+ /// </summary>
100
+ member inline _.Source ( task : Task < Option < _ >>) : Task < Option < _ >> = task
101
+
102
+ /// <summary>
103
+ /// Method lets us transform data types into our internal representation.
104
+ /// </summary>
105
+ member inline _.Source ( async : Async < Option < _ >>) : Task < Option < _ >> = async |> Async.StartAsTask
106
+
120
107
let taskOption = TaskOptionBuilder()
108
+
109
+ [<AutoOpen>]
110
+ // Having members as extensions gives them lower priority in
111
+ // overload resolution and allows skipping more type annotations.
112
+ module TaskOptionCEExtensions =
113
+
114
+ type TaskOptionBuilder with
115
+ /// <summary>
116
+ /// Needed to allow `for..in` and `for..do` functionality
117
+ /// </summary>
118
+ member inline __.Source ( s : #seq<_> ) = s
119
+
120
+ /// <summary>
121
+ /// Method lets us transform data types into our internal representation.
122
+ /// </summary>
123
+ member inline __.Source ( r : Option < 't >) = Task.singleton r
124
+ /// <summary>
125
+ /// Method lets us transform data types into our internal representation.
126
+ /// </summary>
127
+ member inline __.Source ( a : Task < 't >) = a |> Task.map Some
128
+
129
+ /// <summary>
130
+ /// Method lets us transform data types into our internal representation.
131
+ /// </summary>
132
+ member inline __.Source ( a : Async < 't >) = a |> Async.StartAsTask |> Task.map Some
0 commit comments