From 8fe09791c0376acf3ec3c7210819e97049642f0e Mon Sep 17 00:00:00 2001 From: Joshua Clayton Date: Sat, 7 May 2016 15:10:26 -0400 Subject: [PATCH] Extract updateMatches --- src/Unused/DirectoryGrouping.hs | 7 +++---- src/Unused/ResponseFilter.hs | 7 +++++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/Unused/DirectoryGrouping.hs b/src/Unused/DirectoryGrouping.hs index a9b9fb7..e8e99e2 100644 --- a/src/Unused/DirectoryGrouping.hs +++ b/src/Unused/DirectoryGrouping.hs @@ -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 = diff --git a/src/Unused/ResponseFilter.hs b/src/Unused/ResponseFilter.hs index 4b7d28f..170fc6d 100644 --- a/src/Unused/ResponseFilter.hs +++ b/src/Unused/ResponseFilter.hs @@ -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