Extract updateMatches

This commit is contained in:
Joshua Clayton 2016-05-07 15:10:26 -04:00
parent 95b4e13173
commit 8fe09791c0
2 changed files with 10 additions and 4 deletions

View File

@ -7,6 +7,7 @@ import System.FilePath (takeDirectory, splitDirectories)
import qualified Data.Map.Strict as Map
import Data.List (intercalate, sort, nub)
import Unused.Types
import Unused.ResponseFilter (updateMatches)
newtype DirectoryPrefix = DirectoryPrefix String deriving (Eq, Show, Ord)
@ -16,11 +17,9 @@ responsesGroupedByPath pr =
responseForPath :: DirectoryPrefix -> TermMatchSet -> TermMatchSet
responseForPath s =
filterVByPath
updateMatches newMatches
where
filterVByPath = Map.map (updateMatchesWith newMatches)
updateMatchesWith f tr = tr { trMatches = f tr }
newMatches = filter ((== s) . fileNameGrouping . tmPath) . trMatches
newMatches = filter ((== s) . fileNameGrouping . tmPath)
fileNameGrouping :: String -> DirectoryPrefix
fileNameGrouping =

View File

@ -6,6 +6,7 @@ module Unused.ResponseFilter
, isClassOrModule
, railsSingleOkay
, elixirSingleOkay
, updateMatches
) where
import qualified Data.Map.Strict as Map
@ -49,5 +50,11 @@ elixirSingleOkay r =
path (x:_) = x
path [] = ""
updateMatches :: ([TermMatch] -> [TermMatch]) -> TermMatchSet -> TermMatchSet
updateMatches fm =
Map.map (updateMatchesWith $ fm . trMatches)
where
updateMatchesWith f tr = tr { trMatches = f tr }
applyFilter :: (String -> TermResults -> Bool) -> ParseResponse -> ParseResponse
applyFilter = fmap . Map.filterWithKey