-
-
Save dimitris-papadimitriou-chr/05015c87770dcb0b69857e3d57a63504 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.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); | |
public static partial class FuntionalExtensions | |
{ | |
public static Func<Item, bool> AsName(this string @name) => | |
item => item.Name == @name; | |
public static Func<Item, bool> AsId(this int @id) => | |
item => item.Id == @id; | |
public static Func<T, bool> And<T>(this Func<T, bool> @this, Func<T, bool> filter1) => | |
item => @this(item) && filter1(item); | |
public static Func<Func<T, bool>, Func<T, bool>> And<T>(this Func<T, bool> @this) => | |
filter1 => item => @this(item) && filter1(item); | |
public static Func<Item, bool> AsId(this (Func<Item, bool>, int) @this) => | |
@this.Item1.And(@this.Item2.AsId()); | |
public static (Func<Item, bool>, int) And(this Func<Item, bool> @this, int x) => | |
(@this, x); | |
} | |
public class Example | |
{ | |
public static async Task RunAsync() | |
{ | |
List<Item> items = new List<Item> { new Item(1, "a"), new Item(2, "b") }; | |
//IOperationManager<int, string> operationManager = new OperationManager<int, string>().AddLogger(); | |
var filtered0 = items.Where("a".AsName()); | |
var filtered1 = items.Where("a".AsName().And(1.AsId())); | |
var filtered2 = items.Where("a".AsName().And()(1.AsId()).And()(_ => true)); | |
var filtered3 = items.Where("a".AsName().And(1).AsId()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment