Created
August 13, 2020 07:18
-
-
Save shmutalov/07f1746696822ff67bf44b10caffbf66 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Threading.Tasks; | |
namespace KekPuk.Extensions | |
{ | |
/// <summary> | |
/// Task extension methods | |
/// </summary> | |
public static class TaskExt | |
{ | |
public static async Task<TOut> AndThen<TIn, TOut>(this Task<TIn> inputTask, Func<TIn, Task<TOut>> mapperFunc) | |
{ | |
if (mapperFunc == null) throw new ArgumentNullException(nameof(mapperFunc)); | |
return await mapperFunc(await inputTask); | |
} | |
public static async Task AndThen<TIn>(this Task<TIn> inputTask, Action<TIn> mapperFunc) | |
{ | |
if (mapperFunc == null) throw new ArgumentNullException(nameof(mapperFunc)); | |
mapperFunc(await inputTask); | |
} | |
public static async Task<TOut> AndThen<TIn, TOut>(this TIn inputTask, Func<TIn, Task<TOut>> mapperFunc) | |
{ | |
if (mapperFunc == null) throw new ArgumentNullException(nameof(mapperFunc)); | |
return await mapperFunc(inputTask); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment