Reduce into unique addresses

This commit is contained in:
Mats Rauhala 2020-12-10 23:20:38 +02:00
parent c9cf4c1d59
commit a4da4f73da
3 changed files with 24 additions and 6 deletions

View File

@ -35,6 +35,7 @@ library
, text
, bytestring-trie
, vector
, containers
hs-source-dirs: src
default-language: Haskell2010

View File

@ -1,7 +1,7 @@
{ mkDerivation, attoparsec, base, bytestring, bytestring-trie
, conduit, conduit-extra, hedgehog, hedgehog-corpus, HUnit, lens
, mtl, optparse-applicative, stdenv, tasty, tasty-hedgehog
, tasty-hunit, text, vector
, conduit, conduit-extra, containers, hedgehog, hedgehog-corpus
, HUnit, lens, mtl, optparse-applicative, stdenv, tasty
, tasty-hedgehog, tasty-hunit, text, vector
}:
mkDerivation {
pname = "addressbook";
@ -11,7 +11,7 @@ mkDerivation {
isExecutable = true;
libraryHaskellDepends = [
attoparsec base bytestring bytestring-trie conduit conduit-extra
lens mtl text vector
containers lens mtl text vector
];
executableHaskellDepends = [ base optparse-applicative ];
testHaskellDepends = [

View File

@ -9,11 +9,15 @@ import qualified Data.Conduit.Text as CT
import Data.Email
import Data.Email.Header
(Header)
(Header(..))
import System.IO
(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 = await >>= \case
Nothing -> pure ()
@ -21,4 +25,17 @@ combine = await >>= \case
run :: IO ()
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)