From 4139562a49b87509357ebae7a2d5a1d0f6a90127 Mon Sep 17 00:00:00 2001 From: Mats Rauhala Date: Wed, 2 Jan 2019 19:05:44 +0200 Subject: [PATCH] Remove the intermediary list --- src/Main.hs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Main.hs b/src/Main.hs index 1c32ae9..19f767e 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -57,9 +57,8 @@ main :: IO () main = do Cmd{..} <- getRecord "Image duplicate finder" -- XXX: This is a really long line, split it up - fingerprints <- runSafeT (P.fold (\acc -> either (const acc) (\x -> x `seq` x : acc)) [] id (find source (glob "*.jpg" <> regular) >-> P.mapM (\path -> liftIO (putStrLn path) >> fmap (path,) <$> liftIO (readImage path)) >-> P.map (fmap (\(path, img) -> Fingerprint path (fingerprint img))))) - let index = foldl' (flip BK.insert) BK.empty fingerprints - forM_ fingerprints $ \fp -> do + index <- runSafeT (P.fold (\acc -> either (const acc) (\x -> x `seq` BK.insert x acc)) BK.empty id (find source (glob "*.jpg" <> regular) >-> P.mapM (\path -> liftIO (putStrLn path) >> fmap (path,) <$> liftIO (readImage path)) >-> P.map (fmap (\(path, img) -> Fingerprint path (fingerprint img))))) + forM_ index $ \fp -> do let similar = BK.search 1 fp index when (length similar > 1) $ do print similar