public record Product(string Name, decimal Price);
public record Order(string OrderId, string CustomerName, Product[] Products);
public delegate string FormatOrderDelegate(Order order);
public delegate string FormatOrdersDelegate(FormatOrderDelegate formatter, Order[] orders);
public static class InvoiceFormatters
public static FormatOrderDelegate CsvFormatter = order =>
$"{order.OrderId}, {order.CustomerName}, {string.Join(", ", order.Products.Select(p => $"{p.Name} ({p.Price:C})"))}";
public static FormatOrderDelegate JsonFormatter = order =>
$"{{\"OrderId\": \"{order.OrderId}\", \"Customer\": \"{order.CustomerName}\", \"Products\": [{string.Join(", ", order.Products.Select(p => $"{{\"Name\": \"{p.Name}\", \"Price\": {p.Price}}}"))}]}}";
public static FormatOrderDelegate PdfFormatter = order =>
$"Invoice for Order ID: {order.OrderId}\nCustomer: {order.CustomerName}\nProducts:\n{string.Join("\n", order.Products.Select(p => $"- {p.Name}: {p.Price:C}"))}";
public static class InvoiceGenerator
public static string GenerateInvoice(FormatOrderDelegate formatOrder, Order[] orders)
return string.Join("\n", orders.Select(formatOrder.Invoke));
public static class Program
public static void Main()
new Product("Laptop", 1200.00m),
new Product("Mouse", 25.00m),
new Product("Keyboard", 45.00m)
new Order("ORD123", "John Doe", products),
new Order("ORD124", "Jane Smith", products)
var curriedGenerateInvoice = Prelude.curry<FormatOrderDelegate, Order[], string>(InvoiceGenerator.GenerateInvoice);
Func<Order[], string> generateCsvInvoice = curriedGenerateInvoice(InvoiceFormatters.CsvFormatter);
Func<Order[], string> generateJsonInvoice = curriedGenerateInvoice(InvoiceFormatters.JsonFormatter);
Func<Order[], string> generatePdfInvoice = curriedGenerateInvoice(InvoiceFormatters.PdfFormatter);
string csvInvoice = generateCsvInvoice(orders);
string jsonInvoice = generateJsonInvoice(orders);
string pdfInvoice = generatePdfInvoice(orders);
Console.WriteLine("CSV Invoice:");
Console.WriteLine(csvInvoice);
Console.WriteLine("\nJSON Invoice:");
Console.WriteLine(jsonInvoice);
Console.WriteLine("\nPDF Invoice:");
Console.WriteLine(pdfInvoice);