Skip to content

Maybe pr#209

Open
jcranch wants to merge 2 commits intohaskellari:masterfrom
jcranch:maybe-pr
Open

Maybe pr#209
jcranch wants to merge 2 commits intohaskellari:masterfrom
jcranch:maybe-pr

Conversation

@jcranch
Copy link

@jcranch jcranch commented Jun 2, 2025

This adds an function realising an important property of These. I've found the function useful in practice: for example, it allows one to make data structures containing These via mapMaybe. The reverse isomorphism is not really required, since it has coordinates justHere and justThere, which already exist.

I'd be happy putting it in Data.These.Combinators instead; to me it seems just as comfortable in the main file; the division is not very clear-cut.

Comment on lines +87 to +91
maybeThese :: Maybe a -> Maybe b -> Maybe (These a b)
maybeThese (Just x) (Just y) = Just (These x y)
maybeThese (Just x) Nothing = Just (This x)
maybeThese Nothing (Just y) = Just (That y)
maybeThese Nothing Nothing = Nothing
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the way this is just align @Maybe.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments