peschkaj / todo.hs

The greatest todo list app that this team has ever created for CS557
MIT License
0 stars 0 forks source link

Indicate success or failure on adding an event #12

Closed peschkaj closed 6 years ago

peschkaj commented 6 years ago

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)