Suppose, I have this function which accepts a Maybe arg:
func1 :: Maybe Int -> Int
func1 mbArg =
let var1 = case myArg of
Just x -> x
Nothing -> -1
-- ....
I wonder, is there any other way to do the same thing but using something like mapM
, mapM_
or fmap
or <$>
or anything similar? That is, check if it's Just or Nothing and extract the real value or return the default value respectively.
My question is about Maybe as a Monad.