
10 Feb
2008
10 Feb
'08
11:02 a.m.
On Sun, 10 Feb 2008, Michael Feathers wrote:
How bad is this:
addProduct :: [Product] -> Product -> [Product] addProduct inventory product = nub (product : inventory)
compared to this:
addProduct :: [Product] -> Product -> [Product] addProduct inventory p | isNothing (find (==p) inventory) = p : inventory | otherwise = inventory
Data.Set is first choice, 'elem' is second choice, but still better than 'isNothing (find ...)'.