Begin moving away from ParseResponse

This commit is contained in:
Joshua Clayton 2016-05-23 06:35:45 -04:00
parent e006b9c2dd
commit 3f402120d9
2 changed files with 9 additions and 12 deletions

View File

@ -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

View File

@ -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