diff options
author | Teddy Wing | 2017-07-30 19:02:21 +0200 |
---|---|---|
committer | Teddy Wing | 2017-07-30 19:02:21 +0200 |
commit | b4802d1f1fa4f97ff5613c79398c204ebdfcbd75 (patch) | |
tree | b8a07efe6ececf1c552a44325277ef37fc4d594b /src/Plugin.hs | |
parent | bee8faa9804d37e3912e3704dbf03fc1c02eeb84 (diff) | |
download | sorbot-b4802d1f1fa4f97ff5613c79398c204ebdfcbd75.tar.bz2 |
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.
Diffstat (limited to 'src/Plugin.hs')
-rw-r--r-- | src/Plugin.hs | 18 |
1 files changed, 7 insertions, 11 deletions
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 |