Skip to content

Instantly share code, notes, and snippets.

@dzackgarza
Created June 18, 2015 11:08
Show Gist options
  • Save dzackgarza/47740e1d710377938afa to your computer and use it in GitHub Desktop.
Save dzackgarza/47740e1d710377938afa to your computer and use it in GitHub Desktop.
Trying to move a do block within a case assignment
someMaybe :: UserID
someVariable :: Html
simpleRenderFunction :: (Int -> String) -> Html
-- For example, string is a user name: is this a known user?
testCondition :: MonadIO m => String -> m Bool
-- Takes into account the result from the testCondition function.
complicatedRenderFunction :: (Int -> String -> Bool) -> Html
complicatedRenderFunction a s b = case b of ....
------ The way it was done before:
isThisAUser <- testCondition "User1"
let someVariable = complicatedRenderFunction 200 "Hello" isThisAUser
---------
----- Attempted refactor
let someVariable = case someMaybe of
Nothing ->
simpleRenderFunction 200 "Hello"
Just someValue ->
-- evaluate the test condition and use it in the assignment?
testCondition "User1" >>= complicatedRenderFunction 200 "Hello"
-- Evaluates to a bool -- Partially applied, only bool argument needs to be filled?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment