--------------------------------------------------------------------------------
-- Commands

add :: MonadBooks m => Text -> Text -> Maybe Text -> m ()
add title author lname = do
    books <- allBooks
    unless (Set.null $ matches books) $
        throwError "You have already added that book."
    modify $ Set.insert book
    putLn [st|Added #{formatBook book} to the reading list.|]
  where book       = Book title author' (maybe ToBeRead Other lname)
        matches bl = query title bl `Set.intersection` query author bl
        author'    = capitalize author
add :: MonadBooks m => Text -> Text -> Maybe Text -> m ()
add title author lname = do
    books <- allBooks
    unless (Set.null $ matches books) $
        throwError "You have already added that book."
    modify $ Set.insert book
    putLn [st|Added #{formatBook book} to the reading list.|]
  where book       = Book title author' (maybe ToBeRead Other lname)
        matches bl = query title bl `Set.intersection` query author bl
        author'    = capitalize author
add title author lname = do
    books <- allBooks
    unless (Set.null $ matches books) $
        throwError "You have already added that book."
    modify $ Set.insert book
    putLn [st|Added #{formatBook book} to the reading list.|]
  where book       = Book title author' (maybe ToBeRead Other lname)
        matches bl = query title bl `Set.intersection` query author bl
        author'    = capitalize author