Save as trie
This commit is contained in:
parent
22b143aac7
commit
91578bfb03
@ -36,6 +36,7 @@ library
|
||||
, bytestring-trie
|
||||
, vector
|
||||
, containers
|
||||
, filepath
|
||||
hs-source-dirs: src
|
||||
default-language: Haskell2010
|
||||
ghc-options: -Wall
|
||||
|
@ -5,6 +5,7 @@ import qualified Data.Text as T
|
||||
import Conduit
|
||||
import qualified Data.Conduit.Binary as CB
|
||||
import qualified Data.Conduit.Combinators as C
|
||||
import qualified Data.Conduit.List as CL
|
||||
import qualified Data.Conduit.Text as CT
|
||||
|
||||
import Data.Email
|
||||
@ -16,7 +17,14 @@ import System.IO
|
||||
|
||||
import qualified Data.Foldable as F
|
||||
|
||||
import qualified Data.Set as S
|
||||
import qualified Data.Trie as Trie
|
||||
|
||||
import Data.Maybe
|
||||
(fromMaybe)
|
||||
import System.Environment
|
||||
(lookupEnv)
|
||||
import System.FilePath
|
||||
((</>))
|
||||
|
||||
combine :: (MonadUnliftIO m, MonadResource m, MonadThrow m, MonadIO m) => ConduitM FilePath Header m ()
|
||||
combine = await >>= \case
|
||||
@ -25,8 +33,10 @@ combine = await >>= \case
|
||||
|
||||
run :: IO ()
|
||||
run = do
|
||||
x <- runResourceT $ runConduit stream
|
||||
F.for_ x print
|
||||
datDir <- fromMaybe "./" <$> lookupEnv "HOME"
|
||||
runResourceT $ do
|
||||
x <- runConduit stream
|
||||
runConduit (CL.sourceList (Trie.keys x) .| C.map (<> "\n") .| CB.sinkFileCautious (datDir </> ".addressbook.dat"))
|
||||
where
|
||||
separate = \case
|
||||
From x -> [x]
|
||||
@ -38,4 +48,5 @@ run = do
|
||||
.| C.map T.unpack
|
||||
.| combine
|
||||
.| C.concatMap separate
|
||||
.| C.foldMap (S.singleton)
|
||||
.| CT.encode CT.utf8
|
||||
.| C.foldMap (`Trie.singleton` ())
|
||||
|
Loading…
Reference in New Issue
Block a user