2 ms·
> Consider how code would have to change to calculate a deal, such as Buy One Get One Free. There's nothing wrong with passing in a function other than `CartRo
by stickfigure 6y ago
> Consider how code would have to change to calculate a deal, such as Buy One Get One Free.
There's nothing wrong with passing in a function other than `CartRow::getRowPrice`. That's one of the beautiful things about functional programming, you can alter behavior by passing different functions as parameters.
However, as someone who writes ecommerce code that deals with exactly this situation all the time, I can tell you that the question doesn't really make sense. Discounts are usually represented by data in the cart - either a special field, or a negative line item that gets summed along with the others. You don't just mysteriously have a second cheaper item in the cart.