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
you can use fmap
or <$>
like this:
import Control.Applicative ((<$>))
main = do
port <- fromMaybe "4020" <$> lookupEnv "PORT"
putStrLn $ "Listening on:" ++ port
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With