Skip to content

Instantly share code, notes, and snippets.

@therewillbecode
Last active November 11, 2021 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save therewillbecode/470f5c1a48563144ea69e28e96efde43 to your computer and use it in GitHub Desktop.
Save therewillbecode/470f5c1a48563144ea69e28e96efde43 to your computer and use it in GitHub Desktop.
To do List
data User = User { email :: Text }
newtype TodoList = TodoList ([UTCTime, Map TodoId Todo])
newtype UserLists = UserLists (Map Email [TodoList])
newtype TodoId = TodoId Int
data Todo = Todo
{ description :: Description,
status :: Status,
priority :: Priority,
dueDate :: UTCTime
visibility:: Visibility }
data Visibility = Public | Restricted [User]
newtype Description = Description Text
data Status = Done | NotDone
data Priority = Low | Med | High
-- Use a smart constructor to prevent description from being empty.
mkDescription :: Text -> Maybe Description
create :: [(UTCTime, TodoList)]
update :: [(UTCTime, TodoList)] -> TodoId -> Maybe Todo -> [(UTCTime, TodoList)]
view :: TodoList -> TodoId -> Maybe Todo
-- This function simply excludes all todos the user is not permissioned to see.
-- Two optional filter parameters are given to the function.
-- If Just UTC Time is passed then the closest TodoList to that time will be picked.
viewTodos :: Maybe UTCTime -> Maybe Email -> UserLists -> UserLists
closestTodoList :: UTCTime -> Email -> UserLists -> (UTCTime, TodoList)
-- Adding feature B:
-- "Ability to go back into the past, and see what a user's todo list looked like at any point in time."
-- Explain how this would work for todo lists that already exist.
-- To handle existing todo lists I would just put them in the singleton list with a timestamp of the current time now.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment