Reduce into unique addresses
This commit is contained in:
		@@ -35,6 +35,7 @@ library
 | 
				
			|||||||
                     , text
 | 
					                     , text
 | 
				
			||||||
                     , bytestring-trie
 | 
					                     , bytestring-trie
 | 
				
			||||||
                     , vector
 | 
					                     , vector
 | 
				
			||||||
 | 
					                     , containers
 | 
				
			||||||
  hs-source-dirs:      src
 | 
					  hs-source-dirs:      src
 | 
				
			||||||
  default-language:    Haskell2010
 | 
					  default-language:    Haskell2010
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,7 +1,7 @@
 | 
				
			|||||||
{ mkDerivation, attoparsec, base, bytestring, bytestring-trie
 | 
					{ mkDerivation, attoparsec, base, bytestring, bytestring-trie
 | 
				
			||||||
, conduit, conduit-extra, hedgehog, hedgehog-corpus, HUnit, lens
 | 
					, conduit, conduit-extra, containers, hedgehog, hedgehog-corpus
 | 
				
			||||||
, mtl, optparse-applicative, stdenv, tasty, tasty-hedgehog
 | 
					, HUnit, lens, mtl, optparse-applicative, stdenv, tasty
 | 
				
			||||||
, tasty-hunit, text, vector
 | 
					, tasty-hedgehog, tasty-hunit, text, vector
 | 
				
			||||||
}:
 | 
					}:
 | 
				
			||||||
mkDerivation {
 | 
					mkDerivation {
 | 
				
			||||||
  pname = "addressbook";
 | 
					  pname = "addressbook";
 | 
				
			||||||
@@ -11,7 +11,7 @@ mkDerivation {
 | 
				
			|||||||
  isExecutable = true;
 | 
					  isExecutable = true;
 | 
				
			||||||
  libraryHaskellDepends = [
 | 
					  libraryHaskellDepends = [
 | 
				
			||||||
    attoparsec base bytestring bytestring-trie conduit conduit-extra
 | 
					    attoparsec base bytestring bytestring-trie conduit conduit-extra
 | 
				
			||||||
    lens mtl text vector
 | 
					    containers lens mtl text vector
 | 
				
			||||||
  ];
 | 
					  ];
 | 
				
			||||||
  executableHaskellDepends = [ base optparse-applicative ];
 | 
					  executableHaskellDepends = [ base optparse-applicative ];
 | 
				
			||||||
  testHaskellDepends = [
 | 
					  testHaskellDepends = [
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -9,11 +9,15 @@ import qualified Data.Conduit.Text as CT
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import Data.Email
 | 
					import Data.Email
 | 
				
			||||||
import Data.Email.Header
 | 
					import Data.Email.Header
 | 
				
			||||||
       (Header)
 | 
					       (Header(..))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import System.IO
 | 
					import System.IO
 | 
				
			||||||
       (stdin)
 | 
					       (stdin)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import qualified Data.Foldable as F
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import qualified Data.Set as S
 | 
				
			||||||
 | 
					
 | 
				
			||||||
combine :: (MonadUnliftIO m, MonadResource m, MonadThrow m, MonadIO m) => ConduitM FilePath Header m ()
 | 
					combine :: (MonadUnliftIO m, MonadResource m, MonadThrow m, MonadIO m) => ConduitM FilePath Header m ()
 | 
				
			||||||
combine = await >>= \case
 | 
					combine = await >>= \case
 | 
				
			||||||
  Nothing -> pure ()
 | 
					  Nothing -> pure ()
 | 
				
			||||||
@@ -21,4 +25,17 @@ combine = await >>= \case
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
run :: IO ()
 | 
					run :: IO ()
 | 
				
			||||||
run = do
 | 
					run = do
 | 
				
			||||||
  runResourceT $ runConduit (CB.sourceHandle stdin .| CT.decode CT.utf8 .| CT.lines .| C.map T.unpack .| combine .| C.mapM_ (liftIO . print))
 | 
					  x <- runResourceT $ runConduit stream
 | 
				
			||||||
 | 
					  F.for_ x print
 | 
				
			||||||
 | 
					  where
 | 
				
			||||||
 | 
					    separate = \case
 | 
				
			||||||
 | 
					      From x -> [x]
 | 
				
			||||||
 | 
					      To xs -> F.toList xs
 | 
				
			||||||
 | 
					    stream =
 | 
				
			||||||
 | 
					      CB.sourceHandle stdin
 | 
				
			||||||
 | 
					        .| CT.decode CT.utf8
 | 
				
			||||||
 | 
					        .| CT.lines
 | 
				
			||||||
 | 
					        .| C.map T.unpack
 | 
				
			||||||
 | 
					        .| combine
 | 
				
			||||||
 | 
					        .| C.concatMap separate
 | 
				
			||||||
 | 
					        .| C.foldMap (S.singleton)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user