Skip to content

Instantly share code, notes, and snippets.

@abuiles
Created April 27, 2009 00:06
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 abuiles/102227 to your computer and use it in GitHub Desktop.
Save abuiles/102227 to your computer and use it in GitHub Desktop.
{-
-- If the task doesn't exist in the "db" it leaves AppState with the old state
setTaskStatus ::Int -> Bool -> Update AppState Bool
setTaskStatus tid ns =do
(AppState old) <- get
case (adjustTask tid (set_taskStatus ns) old) of
[] -> return False
xs -> do
put (AppState xs)
return True
setTaskDesc :: Int -> B.ByteString -> Update AppState Bool
setTaskDesc tid nd = do
(AppState old) <- get
case (adjustTask tid ((set_taskDescr nd)) old) of
[] -> return False
xs -> do
put (AppState xs)
return True
-}
--Am I scrapping my boiler plate ?
setTaskField :: Int -> (Task -> Task )-> Update AppState Bool
setTaskField tid f = do
s@(AppState old _) <- get
case (adjustTask tid f old) of
[] -> return False
xs -> do
put (s { appdatastore = xs })
return True
setTaskStatus ::Int -> Bool -> Update AppState Bool
setTaskStatus tid ns = setTaskField tid (set_taskStatus ns)
setTaskDesc :: Int -> B.ByteString -> Update AppState Bool
setTaskDesc tid nd = setTaskField tid (set_taskDescr nd)
adjustTask :: Int -> (Task -> Task) -> [Task] ->[Task]
adjustTask tid f tl = let (h,xs) = break (\t -> tId t == tid) tl
in case xs of
r@x:xs' -> f x:h ++ xs'
_ -> []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment