11namespace FsToolkit.ErrorHandling
22
3+ /// <summary>
4+ /// Helper functions for working with the <c>Async</c> type.
5+ /// </summary>
36[<RequireQualifiedAccess>]
47module Async =
58
9+ /// <summary>
10+ /// Converts a value to an <c>Async</c> value
11+ /// </summary>
12+ /// <param name="value">The value to convert to an <c>Async</c> value.</param>
13+ /// <returns>The <c>Async</c> value.</returns>
614 let inline singleton ( value : 'value ) : Async < 'value > =
715 value
816 |> async.Return
917
18+ /// <summary>
19+ /// Converts a value to an <c>Async</c> value
20+ /// </summary>
21+ /// <param name="value">The value to convert to an <c>Async</c> value.</param>
22+ /// <returns>The <c>Async</c> value.</returns>
1023 let inline retn ( value : 'value ) : Async < 'value > =
1124 value
1225 |> async.Return
1326
27+ /// <summary>
28+ /// Takes a transformation function and applies it to the value of an <c>Async</c> value.
29+ /// </summary>
30+ /// <param name="binder">The function to bind over the <c>Async</c> value.</param>
31+ /// <param name="input">The <c>Async</c> value to bind over.</param>
32+ /// <returns>The result of binding the function over the <c>Async</c> value.</returns>
1433 let inline bind
1534 ( [<InlineIfLambda>] binder : 'input -> Async < 'output >)
1635 ( input : Async < 'input >)
1736 : Async < 'output > =
1837 async.Bind( input, binder)
1938
39+ /// <summary>
40+ /// Applies an <c>Async</c> function to an <c>Async</c> value.
41+ /// </summary>
42+ /// <param name="applier">The <c>Async</c> function to apply.</param>
43+ /// <param name="input">The <c>Async</c> value to apply the function to.</param>
44+ /// <returns>The result of applying the function to the value.</returns>
2045 let inline apply ( applier : Async < 'input -> 'output >) ( input : Async < 'input >) : Async < 'output > =
2146 bind ( fun f' -> bind ( fun x' -> singleton ( f' x')) input) applier
2247
48+ /// <summary>
49+ /// Applies a transformation to the value of an <c>Async</c> value to a new <c>Async</c> value using the provided function.
50+ /// </summary>
51+ /// <param name="mapper">The function to apply to the value of the <c>Async</c> value.</param>
52+ /// <param name="input">The <c>Async</c> value to transform.</param>
53+ /// <returns>The transformed <c>Async</c> value.</returns>
2354 let inline map
2455 ( [<InlineIfLambda>] mapper : 'input -> 'output )
2556 ( input : Async < 'input >)
@@ -31,6 +62,13 @@ module Async =
3162 )
3263 input
3364
65+ /// <summary>
66+ /// Applies a transformation to the values of two <c>Async</c> values to a new <c>Async</c> value using the provided function.
67+ /// </summary>
68+ /// <param name="mapper">The function to apply to the values of the <c>Async</c> values.</param>
69+ /// <param name="input1">The first <c>Async</c> value to transform.</param>
70+ /// <param name="input2">The second <c>Async</c> value to transform.</param>
71+ /// <returns>The transformed <c>Async</c> value.</returns>
3472 let inline map2
3573 ( [<InlineIfLambda>] mapper : 'input1 -> 'input2 -> 'output )
3674 ( input1 : Async < 'input1 >)
@@ -47,6 +85,14 @@ module Async =
4785 )
4886 input1
4987
88+ /// <summary>
89+ /// Applies a transformation to the values of three <c>Async</c> values to a new <c>Async</c> value using the provided function.
90+ /// </summary>
91+ /// <param name="mapper">The function to apply to the values of the <c>Async</c> values.</param>
92+ /// <param name="input1">The first <c>Async</c> value to transform.</param>
93+ /// <param name="input2">The second <c>Async</c> value to transform.</param>
94+ /// <param name="input3">The third <c>Async</c> value to transform.</param>
95+ /// <returns>The transformed <c>Async</c> value.</returns>
5096 let inline map3
5197 ( [<InlineIfLambda>] mapper : 'input1 -> 'input2 -> 'input3 -> 'output )
5298 ( input1 : Async < 'input1 >)
@@ -68,21 +114,47 @@ module Async =
68114 )
69115 input1
70116
117+ /// <summary>
71118 /// Takes two asyncs and returns a tuple of the pair
119+ /// </summary>
120+ /// <param name="left">The first async value.</param>
121+ /// <param name="right">The second async value.</param>
122+ /// <returns>The tuple of the pair.</returns>
72123 let inline zip ( left : Async < 'left >) ( right : Async < 'right >) : Async < 'left * 'right > =
73124 bind ( fun l -> bind ( fun r -> singleton ( l, r)) right) left
74125
126+ /// <summary>
127+ /// Operators for working with the <c>Async</c> type.
128+ /// </summary>
75129module AsyncOperators =
76130
131+ /// <summary>
132+ /// Shorthand for <c>Async.map</c>
133+ /// </summary>
134+ /// <param name="mapper">The function to map over the <c>Async</c> value.</param>
135+ /// <param name="input">The <c>Async</c> value to map over.</param>
136+ /// <returns>The result of mapping the function over the <c>Async</c> value.</returns>
77137 let inline (<!>)
78138 ( [<InlineIfLambda>] mapper : 'input -> 'output )
79139 ( input : Async < 'input >)
80140 : Async < 'output > =
81141 Async.map mapper input
82142
143+ /// <summary>
144+ /// Shorthand for <c>Async.apply</c>
145+ /// </summary>
146+ /// <param name="applier">The <c>Async</c> function to apply.</param>
147+ /// <param name="input">The <c>Async</c> value to apply the function to.</param>
148+ /// <returns>The result of applying the function to the value.</returns>
83149 let inline (<*>) ( applier : Async < 'input -> 'output >) ( input : Async < 'input >) : Async < 'output > =
84150 Async.apply applier input
85151
152+ /// <summary>
153+ /// Shorthand for <c>Async.bind</c>
154+ /// </summary>
155+ /// <param name="input">The <c>Async</c> value to bind over.</param>
156+ /// <param name="binder">The function to bind over the <c>Async</c> value.</param>
157+ /// <returns>The result of binding the function over the <c>Async</c> value.</returns>
86158 let inline (>>= )
87159 ( input: Async< 'input>)
88160 ([< InlineIfLambda>] binder: 'input -> Async< 'output>)
0 commit comments