Skip to content

Instantly share code, notes, and snippets.

@nurpax
Created February 23, 2017 12:40
Show Gist options
  • Save nurpax/93d4f4386f0ee58234c788f32b5b39e3 to your computer and use it in GitHub Desktop.
Save nurpax/93d4f4386f0ee58234c788f32b5b39e3 to your computer and use it in GitHub Desktop.
import Data.Maybe
import System.IO (readFile)
-- Open a file and process its contents with action, or return the default value 'deflt'
maybeWithFile :: Maybe FilePath -> b -> (String -> b) -> IO b
maybeWithFile fname deflt action = maybe (return deflt) (fmap action . readFile) fname
main :: IO ()
main = do
let inactiveWhitelist = Just "whitelist.txt"
whitelist <- maybeWithFile inactiveWhitelist [] $ \contents -> words contents
print whitelist
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment