Reputation: 16059
I feel like I should already know this, but how could I use fromMaybe
in one line instead of breaking it into 2 with a let
?
main = do
maybePort <- lookupEnv "PORT"
let port = fromMaybe "4020" maybePort
putStrLn $ "Listening on:" ++ port
Upvotes: 4
Views: 94
Reputation: 52280
you can use fmap
or <$>
like this:
import Control.Applicative ((<$>))
main = do
port <- fromMaybe "4020" <$> lookupEnv "PORT"
putStrLn $ "Listening on:" ++ port
Upvotes: 8