C
C#2mo ago
TahaA

Comments in curried lambda expression

Just a quick question. Do you think the comments I used here are correct? If needed I'll provide the whole code:
public static Func<double, Func<double, double>> GetPriceCalculator(double taxRate)
{
Func<double /*discount*/, Func<double /*price*/, double/*final price*/>> GetFinalPrice = discount => price => price * (1 - discount) * (1 + taxRate);
return GetFinalPrice;
}
public static Func<double, Func<double, double>> GetPriceCalculator(double taxRate)
{
Func<double /*discount*/, Func<double /*price*/, double/*final price*/>> GetFinalPrice = discount => price => price * (1 - discount) * (1 + taxRate);
return GetFinalPrice;
}
7 Replies
canton7
canton72mo ago
Looks correct, but took me a while to get my head around it
TahaA
TahaA2mo ago
understandable, that's the struggle with code that's put into one line as much as possible
canton7
canton72mo ago
That might well benefit from some custom delegates, with named parameters. Otherwise you're having to work out what each unnamed double actually means
TahaA
TahaA2mo ago
I see. Thanks
canton7
canton72mo ago
And PriceCalculator doesn't really capture the fact that you give it a discount, and it gives you back a function which turns a price into a final price (with discount and tax)
TahaA
TahaA2mo ago
yeah I know, but I was asking because this was part of a classroom assignment. It worked but I didn't know why it worked, so I was asking to be sure
canton7
canton72mo ago
👍