Skip to content
This repository was archived by the owner on Sep 20, 2021. It is now read-only.

Commit 1e92986

Browse files
committed
Simplified some expressions with LambdaCase language extension
1 parent d882e21 commit 1e92986

File tree

6 files changed

+15
-11
lines changed

6 files changed

+15
-11
lines changed

postgresql-simple-migration.cabal

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Library
3535
Database.PostgreSQL.Simple.Util
3636
hs-source-dirs: src
3737
ghc-options: -Wall -fwarn-tabs -fwarn-incomplete-uni-patterns
38-
default-extensions: OverloadedStrings, CPP
38+
default-extensions: OverloadedStrings, CPP, LambdaCase
3939
default-language: Haskell2010
4040
build-depends: base >= 4.6 && < 5.0,
4141
base64-bytestring >= 1.0 && < 1.1,
@@ -49,7 +49,7 @@ Executable migrate
4949
main-is: Main.hs
5050
hs-source-dirs: src
5151
ghc-options: -Wall -fwarn-tabs -fwarn-incomplete-uni-patterns
52-
default-extensions: OverloadedStrings, CPP
52+
default-extensions: OverloadedStrings, CPP, LambdaCase
5353
default-language: Haskell2010
5454
build-depends: base >= 4.6 && < 5.0,
5555
base64-bytestring >= 1.0 && < 1.1,
@@ -64,7 +64,7 @@ test-suite tests
6464
main-is: Main.hs
6565
hs-source-dirs: test
6666
ghc-options: -Wall -fwarn-tabs -fwarn-incomplete-uni-patterns
67-
default-extensions: OverloadedStrings, CPP
67+
default-extensions: OverloadedStrings, CPP, LambdaCase
6868
default-language: Haskell2010
6969
type: exitcode-stdio-1.0
7070
build-depends: base >= 4.6 && < 5.0,

src/Database/PostgreSQL/Simple/Migration.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
{-# LANGUAGE CPP #-}
1515
{-# LANGUAGE OverloadedStrings #-}
16+
{-# LANGUAGE LambdaCase #-}
1617

1718
module Database.PostgreSQL.Simple.Migration
1819
(
@@ -101,7 +102,7 @@ scriptsInDirectory dir =
101102
executeMigration :: Connection -> Bool -> ScriptName -> BS.ByteString -> IO (MigrationResult String)
102103
executeMigration con verbose name contents = do
103104
let checksum = md5Hash contents
104-
checkScript con name checksum >>= \r -> case r of
105+
checkScript con name checksum >>= \case
105106
ScriptOk -> do
106107
when verbose $ putStrLn $ "Ok:\t" ++ name
107108
return MigrationSuccess
@@ -155,7 +156,7 @@ executeValidation con verbose cmd = case cmd of
155156
return MigrationSuccess
156157
where
157158
validate name contents =
158-
checkScript con name (md5Hash contents) >>= \r -> case r of
159+
checkScript con name (md5Hash contents) >>= \case
159160
ScriptOk -> do
160161
when verbose $ putStrLn $ "Ok:\t" ++ name
161162
return MigrationSuccess
@@ -168,8 +169,7 @@ executeValidation con verbose cmd = case cmd of
168169

169170
goScripts _ [] = return MigrationSuccess
170171
goScripts path (x:xs) = do
171-
r <- validate x =<< BS.readFile (path ++ "/" ++ x)
172-
case r of
172+
(validate x =<< BS.readFile (path ++ "/" ++ x)) >>= \case
173173
e@(MigrationError _) ->
174174
return e
175175
MigrationSuccess ->
@@ -182,7 +182,7 @@ executeValidation con verbose cmd = case cmd of
182182
-- will be executed and its meta-information will be recorded.
183183
checkScript :: Connection -> ScriptName -> Checksum -> IO CheckScriptResult
184184
checkScript con name checksum =
185-
query con q (Only name) >>= \r -> case r of
185+
query con q (Only name) >>= \case
186186
[] ->
187187
return ScriptNotExecuted
188188
Only actualChecksum:_ | checksum == actualChecksum ->

src/Database/PostgreSQL/Simple/Util.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
{-# LANGUAGE CPP #-}
1313
{-# LANGUAGE OverloadedStrings #-}
14+
{-# LANGUAGE LambdaCase #-}
1415

1516
module Database.PostgreSQL.Simple.Util
1617
( existsTable

src/Main.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
{-# LANGUAGE CPP #-}
1313
{-# LANGUAGE OverloadedStrings #-}
14+
{-# LANGUAGE LambdaCase #-}
1415

1516
module Main (
1617
main
@@ -35,7 +36,7 @@ import qualified Data.Text as T
3536
import qualified Data.Text.Encoding as T
3637

3738
main :: IO ()
38-
main = getArgs >>= \args -> case args of
39+
main = getArgs >>= \case
3940
"-h":_ ->
4041
printUsage
4142
"-q":xs ->

test/Database/PostgreSQL/Simple/MigrationTest.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
-- A collection of postgresql-simple-migration specifications.
1111

1212
{-# LANGUAGE OverloadedStrings #-}
13-
{-# LANGUAGE CPP #-}
13+
{-# LANGUAGE CPP #-}
14+
{-# LANGUAGE LambdaCase #-}
1415

1516
module Database.PostgreSQL.Simple.MigrationTest where
1617

test/Main.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
-- The test entry-point for postgresql-simple-migration.
1111

1212
{-# LANGUAGE OverloadedStrings #-}
13-
{-# LANGUAGE CPP #-}
13+
{-# LANGUAGE CPP #-}
14+
{-# LANGUAGE LambdaCase #-}
1415

1516
module Main
1617
( main

0 commit comments

Comments
 (0)