Re:Show HN: I built a poker site with Haskell
by enobayram on Sunday August 11, 2019 @01:26AM
(#20666408)
here's ho I'd write it:
[ Parent
| on HN ]
Re:Show HN: I built a poker site with Haskell
by enobayram on Sunday August 11, 2019 @01:38AM
(#20666454)
Though I should add that it's in general against the Haskell spirit to write code against needlessly specific types and to combine unrelated functionality. So, I'd first look for a function or write one myself in some utils module that looks up and parses a value from an environment variable:
readEnv :: Read a => String -> IO (Maybe a)
readEnv var = (readMaybe =<<) <$> lookupEnv var
Then the function in question becomes much easier (and probably unnnecessary too): getSocketAPIPort defaultPort = fromMaybe defaultPort <$> readEnv "socketPort"