I have the following code, and I think it is ugly:
loginCheck = do
ml <- getPostParam "login" -- ml and mp :: Maybe ByteString
mp <- getPostParam "password"
if isJust ml && isJust mp
then authAs (fromJust ml) (fromJust mp)
else render "Msg" [("text", "Form incomplete")]
This code seems to be very imperative. Can I simplify it somehow?
As others have suggested,
Applicativecould be nice here, as well asMaybeTdepending on the context. A third thing you might keep in mind is that a pattern match failure in adoblock binding callsfail.This is what I would do:
Or a solution with
MaybeT, albeit one with a different return value (again more context might show this to be a good approach or not):…actually the above is rather hokey now that I look at it