Right now, event success or failure is silent apart from printing to STDOUT. We need a better way to indicate if an event was actually added.
One approach would be to use the Either type so that we can determine success (left) or failure (right).
We can accomplish this by changing the existing code to something like:
addEvent :: Event -> [Event] -> IO [Event]
addEvent e es = either return save $ addEventToList e es
where save xs = do
encodeFile eventFile xs
return xs
addEventToList :: Event -> [Event] -> Either [Event] [Event]
addEventToList x es = if existingEvent x es then Left es else Right (x:es)
Right now, event success or failure is silent apart from printing to
STDOUT
. We need a better way to indicate if an event was actually added.One approach would be to use the
Either
type so that we can determine success (left) or failure (right).We can accomplish this by changing the existing code to something like: