This seems a long shot, but recently I've had a need for the following:
mjoin :: (Monoid b, Monad m) => m b -> m b -> m b
mjoin a b = do
a' <- a
b' <- b
return $ mappend a' b'
The example use is this:
> mjoin (Just [1,2,3]) (Just [4, 5, 6])
Just [1,2,3,4,5,6]
> mjoin (Just [1,2,3]) Nothing
Nothing
> mjoin Nothing (Just [4, 5, 6])
Nothing
In other words, if either parameters are Nothing
, then return Nothing
. Else, return Just
and the appended values.
Is there a standard function for this or a simpler formulation, perhaps with >>=
?
Perhaps something like this:
mjoin :: (Monoid b, Monad m) => m b -> m b -> m b
mjoin = liftM2 mappend
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With