forked from louthy/language-ext
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTask.Try.Extensions.cs
48 lines (45 loc) · 2.36 KB
/
Task.Try.Extensions.cs
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
using System;
using System.Diagnostics.Contracts;
using System.Threading.Tasks;
namespace LanguageExt
{
public static class TaskTryRxExtensions
{
/// <summary>
/// Turns the computation into an observable stream
/// </summary>
/// <typeparam name="A">Bound type</typeparam>
/// <typeparam name="R">Returned observable bound type</typeparam>
/// <param name="self">This</param>
/// <param name="Succ">Function to call when the operation succeeds</param>
/// <param name="Fail">Function to call when the operation fails</param>
/// <returns>An observable that represents the result of Succ or Fail</returns>
[Pure]
public static IObservable<R> MatchObservable<A, R>(this Task<Try<A>> self, Func<A, IObservable<R>> Succ, Func<Exception, R> Fail) =>
self.ToAsync().MatchObservable(Succ, Fail);
/// <summary>
/// Turns the computation into an observable stream
/// </summary>
/// <typeparam name="A">Bound type</typeparam>
/// <typeparam name="R">Returned observable bound type</typeparam>
/// <param name="self">This</param>
/// <param name="Succ">Function to call when the operation succeeds</param>
/// <param name="Fail">Function to call when the operation fails</param>
/// <returns>An observable that represents the result of Succ or Fail</returns>
[Pure]
public static IObservable<R> MatchObservable<A, R>(this Task<Try<A>> self, Func<A, IObservable<R>> Succ, Func<Exception, IObservable<R>> Fail) =>
self.ToAsync().MatchObservable(Succ, Fail);
/// <summary>
/// Turns the computation into an observable stream
/// </summary>
/// <typeparam name="A">Bound type</typeparam>
/// <typeparam name="R">Returned observable bound type</typeparam>
/// <param name="self">This</param>
/// <param name="Succ">Function to call when the operation succeeds</param>
/// <param name="Fail">Function to call when the operation fails</param>
/// <returns>An observable that represents the result of Succ or Fail</returns>
[Pure]
public static IObservable<R> MatchObservable<A, R>(this Task<Try<A>> self, Func<A, R> Succ, Func<Exception, IObservable<R>> Fail) =>
self.ToAsync().MatchObservable(Succ, Fail);
}
}