Created
June 15, 2020 02:46
-
-
Save vst/f4a82377f1b3a3aa2113b740802993c2 to your computer and use it in GitHub Desktop.
Demonstrate how to use Stack for scripts (+email address validation)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{- stack script | |
--resolver lts-16.0 | |
--package bytestring | |
--package email-validate | |
--ghc-options -Wall | |
--install-ghc | |
--compile | |
-} | |
-- * Command Line Usage: | |
-- | |
-- >>> echo "invalid\[email protected]" | stack ParseEmail.hs | |
-- - invalid (at sign > @: not enough input) | |
-- + [email protected] | |
{-# LANGUAGE OverloadedStrings #-} | |
import qualified Data.ByteString.Char8 as BC | |
import System.IO (stderr) | |
import Text.Email.Validate (validate) | |
main :: IO () | |
main = mapM_ validateAndShow =<< BC.lines <$> BC.getContents | |
validateAndShow :: BC.ByteString -> IO () | |
validateAndShow s = | |
case validate s of | |
Left e -> BC.hPutStrLn stderr ("- " <> s <> " (" <> BC.pack e <> ")") | |
Right _ -> BC.putStrLn ("+ " <> s) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment