mirror of
https://github.com/joshuaclayton/unused.git
synced 2024-09-11 04:45:28 +03:00
Extract updateMatches
This commit is contained in:
parent
95b4e13173
commit
8fe09791c0
@ -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 =
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user