diff --git a/app/Main.hs b/app/Main.hs index 3e672a9..8a90348 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -4,7 +4,7 @@ import Options.Applicative import System.IO (hSetBuffering, BufferMode(NoBuffering), stdout) import Data.Maybe (fromMaybe) import Unused.Parser (parseLines) -import Unused.Types (ParseResponse, RemovalLikelihood(..)) +import Unused.Types (TermMatchSet, RemovalLikelihood(..)) import Unused.ResultsClassifier import Unused.ResponseFilter (withOneOccurrence, withLikelihoods, ignoringPaths) import Unused.Grouping (CurrentGrouping(..), groupedResponses) @@ -54,7 +54,7 @@ run options = withoutCursor $ do resetScreen either printParseError (printSearchResults . groupedResponses (oGrouping options)) $ - optionFilters options response + fmap (optionFilters options) response return () @@ -73,7 +73,7 @@ withInfo :: Parser a -> String -> String -> String -> ParserInfo a withInfo opts h d f = info (helper <*> opts) $ header h <> progDesc d <> footer f -optionFilters :: Options -> (ParseResponse -> ParseResponse) +optionFilters :: Options -> (TermMatchSet -> TermMatchSet) optionFilters o = foldl1 (.) filters where diff --git a/src/Unused/ResponseFilter.hs b/src/Unused/ResponseFilter.hs index dea4291..2c682fd 100644 --- a/src/Unused/ResponseFilter.hs +++ b/src/Unused/ResponseFilter.hs @@ -14,19 +14,19 @@ import Unused.Regex (matchRegex) import Unused.Types import Unused.ResultsClassifier -withOneOccurrence :: ParseResponse -> ParseResponse -withOneOccurrence = applyFilter (const oneOccurence) +withOneOccurrence :: TermMatchSet -> TermMatchSet +withOneOccurrence = Map.filterWithKey (const oneOccurence) oneOccurence :: TermResults -> Bool oneOccurence = (== 1) . totalOccurrenceCount -withLikelihoods :: [RemovalLikelihood] -> ParseResponse -> ParseResponse +withLikelihoods :: [RemovalLikelihood] -> TermMatchSet -> TermMatchSet withLikelihoods [] = id -withLikelihoods l = applyFilter (const $ includesLikelihood l) +withLikelihoods l = Map.filterWithKey (const $ includesLikelihood l) -ignoringPaths :: [String] -> ParseResponse -> ParseResponse +ignoringPaths :: [String] -> TermMatchSet -> TermMatchSet ignoringPaths xs = - fmap (updateMatches newMatches) + updateMatches newMatches where newMatches = filter (not . matchesPath . tmPath) matchesPath p = any (`isInfixOf` p) xs @@ -71,8 +71,5 @@ updateMatches fm = where updateMatchesWith f tr = tr { trMatches = f tr } -applyFilter :: (String -> TermResults -> Bool) -> ParseResponse -> ParseResponse -applyFilter = fmap . Map.filterWithKey - isAllowedTerm :: TermResults -> [String] -> Bool isAllowedTerm = elem . trTerm