Convert (maybe a, b) to Maybe (a, b)
4 answers
You can also use Bitraversable
:
bitraverse id pure :: (Bitraversable t, Applicative f) => t (f c) d -> f (t c d)
which specializes in
bitraverse id pure :: (Maybe a, b) -> Maybe (a, b)
+7
source to share
Yes. Functors.
solution :: (Maybe a, b) -> Maybe (a, b)
solution (a, b) = fmap (\q -> (q, b)) a
Or, in a style without spaces:
solution = uncurry $ flip $ fmap . flip (,)
Also, as @Bakuriu said, if you include TupleSections
and Control.Applicative
, it becomes very simple:
solution (a, b) = (, b) <$> a
More details here .
+5
source to share