From 487f8f805647d3f3fbb86aac6838f0c0e37a6bde Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 30 Jul 2017 19:07:11 +0200 Subject: Add a type for plugin actions Instead of implicitly using `String -> String` as the type for plugin action/perform functions, create a real type to represent this. --- src/Plugin.hs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/Plugin.hs b/src/Plugin.hs index 2a06fb4..6522e0b 100644 --- a/src/Plugin.hs +++ b/src/Plugin.hs @@ -7,9 +7,11 @@ module Plugin import Text.Regex.TDFA +type PluginAction = String -> String + data Plugin = Plugin { matchRegex :: String - , perform :: String -> String + , perform :: PluginAction } instance Show Plugin where @@ -24,7 +26,6 @@ matchPlugin message = firstPlugin $ matchPlugins message plugins matchPlugins :: String -> [Plugin] -> [Plugin] matchPlugins message plugins = [p | p <- plugins, message =~ matchRegex p] --- TODO: Make a type for the `perform` function performPlugin :: Plugin -> String -> String performPlugin p message = perform p $ message =~ matchRegex p @@ -33,7 +34,7 @@ gitHubCommit = Plugin , perform = gitHubCommitAction } -gitHubCommitAction :: String -> String +gitHubCommitAction :: PluginAction gitHubCommitAction match = "https://github.com/" ++ match plugins :: [Plugin] -- cgit v1.2.3