Why return a cart object when calling addToCart(..)
GrumpyProgrammer
12
Why return a cart object when calling addToCart(..) ?
Because in the functional programming context, we do not mutate shared state. Since we can’t add to the shared state of the cart that gets passed in, we must return a new cart with the additions made.
In other words, the job isn’t done unless the new cart is returned.