From b4802d1f1fa4f97ff5613c79398c204ebdfcbd75 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 30 Jul 2017 19:02:21 +0200 Subject: Get rid of `realMatchPlugin` I didn't even need the `matchPlugin` that took `plugins` as an argument, I can just use the `plugins` function directly in `matchPlugin`. Get rid of `realMatchPlugin` because that was just a temporary name until I got things working. Move `firstPlugin` into the definition of `matchPlugin` because it's not needed anywhere else and is just used to pattern match for the first matched plugin in the list. --- src/Lib.hs | 2 +- src/Plugin.hs | 18 +++++++----------- 2 files changed, 8 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/Lib.hs b/src/Lib.hs index abb8fe7..0142dfb 100644 --- a/src/Lib.hs +++ b/src/Lib.hs @@ -9,5 +9,5 @@ import Plugin someFunc :: IO () someFunc = do let message = "75ac7b18a009ffe7a77a17a61d95c01395f36b44" - Just plugin = realMatchPlugin message + Just plugin = matchPlugin message putStrLn $ performPlugin plugin message diff --git a/src/Plugin.hs b/src/Plugin.hs index e25a1dc..2a06fb4 100644 --- a/src/Plugin.hs +++ b/src/Plugin.hs @@ -1,6 +1,6 @@ module Plugin - ( realMatchPlugin - , Plugin + ( Plugin + , matchPlugin , performPlugin , plugins ) where @@ -15,19 +15,15 @@ data Plugin = Plugin instance Show Plugin where show (Plugin r p) = "matchRegex = " ++ r -realMatchPlugin :: String -> Maybe Plugin -realMatchPlugin message = matchPlugin message plugins - -matchPlugin :: String -> [Plugin] -> Maybe Plugin -matchPlugin message plugins = firstPlugin $ matchPlugins message plugins +matchPlugin :: String -> Maybe Plugin +matchPlugin message = firstPlugin $ matchPlugins message plugins + where + firstPlugin [] = Nothing + firstPlugin (p:ps) = Just p matchPlugins :: String -> [Plugin] -> [Plugin] matchPlugins message plugins = [p | p <- plugins, message =~ matchRegex p] -firstPlugin :: [Plugin] -> Maybe Plugin -firstPlugin [] = Nothing -firstPlugin (p:ps) = Just p - -- TODO: Make a type for the `perform` function performPlugin :: Plugin -> String -> String performPlugin p message = perform p $ message =~ matchRegex p -- cgit v1.2.3