I have a function like so
foo :: X -> Y -> Z
and I have two separate calculations that are done to get my variables of type X and Y, but they can fail, so I use a Maybe
calc1 :: A -> Maybe X
calc2 :: B -> Maybe Y
now I am not sure how to use the monad operations to get this desired behaviour
safe_foo :: Maybe X -> Maybe Y -> Maybe Z
safe_foo Nothing _ = Nothing
safe_foo _ Nothing = Nothing
safe_foo (Just x) (Just y) = Just (foo x y)
what is the best way to do this?