When I use fmap
over a value, it essentially "unboxes" that value, applies the function to it, and boxes it back up.
For example:
-- returns Just 8
fmap (+3) (Just 5)
Is there any function that gives me the value without boxing it back up?
-- returns 8
fmap_2 (+3) (Just 5)
Granted, I don't know how this would work for arrays, but it would be useful for Either
s and Maybe
s, for starters. I could also use it to mix Monads easily:
-- myfunc :: Maybe Int
-- if myfunc returned a Just, show it and then print it. Otherwise, print 'Nothing'.
putStrLn . fmap show $ myfunc
Or is there another standard way of mixing Monads?