From 87b582f1629eda8e7a91ba5ccbea8aa74291885c Mon Sep 17 00:00:00 2001 From: Mattias Nordqvist Date: Wed, 4 Oct 2023 13:10:20 +0200 Subject: [PATCH] . --- Results/DotNetThoughts.Results.csproj | 2 +- Results/Tap.cs | 30 +++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/Results/DotNetThoughts.Results.csproj b/Results/DotNetThoughts.Results.csproj index a4f227e..2d65d7c 100644 --- a/Results/DotNetThoughts.Results.csproj +++ b/Results/DotNetThoughts.Results.csproj @@ -4,7 +4,7 @@ net7.0 enable enable - 1.3.0 + 1.4.0 True MIT diff --git a/Results/Tap.cs b/Results/Tap.cs index 189bd20..f9a841d 100644 --- a/Results/Tap.cs +++ b/Results/Tap.cs @@ -1,6 +1,9 @@ namespace DotNetThoughts.Results; public static partial class Extensions { + /// + /// Tap into the result and perform an action if the result is successful. + /// public static Result Tap(this Result source, Action next) { if (source.Success) @@ -10,12 +13,39 @@ public static Result Tap(this Result source, Action next) return source; } + /// + /// Tap into the result and perform an action if the result is successful. + /// public static async Task> Tap(this Task> source, Action next) { if ((await source).Success) { next((await source).Value); } + return await source; + } + + /// + /// Tap into the result and perform an action if the result is successful. + /// + public static async Task> Tap(this Task> source, Func next) + { + if ((await source).Success) + { + await next((await source).Value); + } + return await source; + } + + /// + /// Tap into the result and perform an action if the result is successful. + /// + public static async Task> Tap(this Result source, Func next) + { + if (source.Success) + { + await next(source.Value); + } return source; } }