Created
April 27, 2009 00:06
-
-
Save abuiles/102227 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{- | |
-- 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