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.Collections.Generic; | |
using System.Diagnostics; | |
using System.Linq; | |
using System.Threading.Tasks; | |
namespace FunctionalExperimentation.SimpleRefactorings.Medium1.ExtensionsDecorator | |
{ | |
public record struct Item(int Id, string Name); |
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
public delegate Task<R> Operation<T, R>(T t); | |
public static partial class FuntionalExtensions | |
{ | |
public static Operation<T, R> AddDebugLogging<T, R>(this Operation<T, R> @this) => | |
(T t) => | |
{ | |
var result = @this(t); | |
Debug.WriteLine(result); | |
return result; |
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
public interface IOperation<T, R> | |
{ | |
Task<R> OperationAsync(T t); | |
} |
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
public record class OperationManager<T, R>(IOperation<T, R> operation) | |
{ | |
public R ExecuteActivity(T t) | |
{ | |
//do some stuff1 | |
//... | |
return operation.OperationAsync(t).Result; | |
} | |
} |
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 FunctionalExperimentation.FuncTaskCovarinat.Minimal.DelegateAdapter | |
{ | |
public static partial class F | |
{ | |
public static FuncTask<T> ToFuncTask<T>(this Func<Task<T>> @this) => | |
new FuncTask<T>( | |
()=>@this().GetAwaiter().GetResult() |
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 FunctionalExperimentation.SimpleRefactorings.Medium.FuncTaskCovarinat.Minimal | |
{ | |
public static partial class F | |
{ | |
public static FuncTask<T> ToFuncTask<T>(this Func<Task<T>> @this) => | |
new FuncTask<T>( | |
() => @this().GetAwaiter().GetResult() |
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 FunctionalExperimentation.Practical.FuncTaskCovarinat | |
{ | |
public static partial class F | |
{ | |
public static IFuncTask<T> ToWithResult<T>(this Func<Task<T>> @this) => new FuncTaskAdapter<T>(@this); | |
public static T GetOrThrowIfNull<T>(this IFuncTask<T> @this, string message) | |
{ |
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
Func<(int OrderNum, string ProductName),(int orderPlacementId, int orderStatus)> | |
printOrderDetails = command => { ... }; |
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
public class Printer | |
{ | |
public (int orderPlacementId, int orderStatus) PrintOrderDetails( | |
(int OrderNum, string ProductName) command) | |
{ | |
... | |
} | |
} |
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
public class Order | |
{ | |
IList<Product> Products { get; } | |
public Order(IList<Product> products) => Products = products; | |
public double GetTotalPrice(IDiscountStrategy activeDiscount) => | |
Products | |
.Select(activeDiscount.GetDiscountedPrice) | |
.Sum(); |
NewerOlder