How to use non-monodic functions in a binding operation

It seems to me that I already knew about this, but how could I use it fromMaybeon one line and not split it into 2 with let?

main = do
    maybePort <- lookupEnv "PORT"
    let port = fromMaybe "4020" maybePort
    putStrLn $ "Listening on:" ++ port
+4
source share
1 answer

you can use fmapeither <$>as follows:

import Control.Applicative ((<$>))

main = do
    port <- fromMaybe "4020" <$> lookupEnv "PORT"
    putStrLn $ "Listening on:" ++ port
+8
source

All Articles