Hi
Basically I've got the following code.
- What it does is it takes two input the itemName and the sectionName
- checks if the input is equal to any item in the list (test database) and increment it
- prints the modified list
It does what it needs to do but when I try to increment the amount of sales for apple the output doubles the record of the apple. someone told me that I should try list comprehension but got no idea of how to use it, im a total beginner and would appreciate a step by step explanation :)
Input Code:
items :: [Grocery]
items = [("Water", "Drink Section", 1),
("Squash", "Drink Section", 1),
("Apple", "Fruit Section", 1),
("Plates", "Disposable Section", 1),
("Plates", "Ceramic Section", 1)]
sales:: [database] -> String -> String-> [database]
sales db itemName sectionName = []
sales ((item, section, qty): xs) itemName sectionName
| item == itemName && section== sectionName = [(item, section, qty + 1)] sales xs itemName sectionName
| otherwise = sales xs itemName sectionName
Current Output:
[("Apple", "Fruit Section", 2),
("Water", "Drink Section", 1),
("Squash", "Drink Section", 1),
("Apple", "Fruit Section", 1),
("Plates", "Disposable Section", 1),
("Plates", "Ceramic Section", 1)]
Thank You!