Open Gurkenglas opened 8 years ago
You can use the fmap
function for that. It will only operate on the Just
values
fmap :: (a -> b) -> Maybe a -> Maybe b
@nikivazou How would it be used in this case? Specifically, here's what @Gurkenglas wants to do:
data Letter = A | B | C | D | E | ...
main = do
-- This should print "Nothing"
print $ caseMay C of
A -> 'a'
B -> 'b'
-- This should print "Just 'a'"
print $ caseMay A of
A -> 'a'
B -> 'b'
Oh sorry, I though you were matching against Maybe
values.
I see, so you are adding this _ -> Nothing
case on your match! It is not a bad idea.
would be desugared to
. Then there would be the corresponding LambdaCase equivalent and perhaps this would all be generalized to any Alternative. Compare fail's use in do notation.