Prettify monads

This commit is contained in:
calebmer
2015-11-12 15:09:28 -05:00
parent 2f6254f44c
commit 3794d358b4
+5 -14
View File
@@ -238,11 +238,9 @@ columnFromRow :: [Table] ->
Bool, Maybe Int, Maybe Int, Bool, Maybe Int, Maybe Int,
Maybe Text, Maybe Text) Maybe Text, Maybe Text)
-> Maybe Column -> Maybe Column
columnFromRow tabs (s, t, n, pos, nul, typ, u, l, p, d, e) = columnFromRow tabs (s, t, n, pos, nul, typ, u, l, p, d, e) = buildColumn <$> table
if isJust table
then Just $ Column (fromJust table) n pos nul typ u l p d (parseEnum e) Nothing
else Nothing
where where
buildColumn tbl = Column tbl n pos nul typ u l p d (parseEnum e) Nothing
table = find (\tbl -> tableSchema tbl == s && tableName tbl == t) tabs table = find (\tbl -> tableSchema tbl == s && tableName tbl == t) tabs
parseEnum :: Maybe Text -> [Text] parseEnum :: Maybe Text -> [Text]
parseEnum str = fromMaybe [] $ split (==',') <$> str parseEnum str = fromMaybe [] $ split (==',') <$> str
@@ -310,12 +308,8 @@ allPrimaryKeys tabs = do
return $ mapMaybe (pkFromRow tabs) pks return $ mapMaybe (pkFromRow tabs) pks
pkFromRow :: [Table] -> (Schema, Text, Text) -> Maybe PrimaryKey pkFromRow :: [Table] -> (Schema, Text, Text) -> Maybe PrimaryKey
pkFromRow tabs (s, t, n) = pkFromRow tabs (s, t, n) = PrimaryKey <$> table <*> pure n
if isJust table where table = find (\tbl -> tableSchema tbl == s && tableName tbl == t) tabs
then Just $ PrimaryKey (fromJust table) n
else Nothing
where
table = find (\tbl -> tableSchema tbl == s && tableName tbl == t) tabs
allSynonyms :: [Column] -> H.Tx P.Postgres s [(Column,Column)] allSynonyms :: [Column] -> H.Tx P.Postgres s [(Column,Column)]
allSynonyms allCols = do allSynonyms allCols = do
@@ -353,10 +347,7 @@ allSynonyms allCols = do
return $ mapMaybe (synonymFromRow allCols) syns return $ mapMaybe (synonymFromRow allCols) syns
synonymFromRow :: [Column] -> (Text,Text,Text,Text,Text,Text) -> Maybe (Column,Column) synonymFromRow :: [Column] -> (Text,Text,Text,Text,Text,Text) -> Maybe (Column,Column)
synonymFromRow allCols (s1,t1,c1,s2,t2,c2) = synonymFromRow allCols (s1,t1,c1,s2,t2,c2) = (,) <$> col1 <*> col2
if isJust col1 && isJust col2
then Just (fromJust col1,fromJust col2)
else Nothing
where where
col1 = findCol s1 t1 c1 col1 = findCol s1 t1 c1
col2 = findCol s2 t2 c2 col2 = findCol s2 t2 c2