Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Make Maybe an instance of FromField and ToField

  • Loading branch information...
commit 19bc4ca222d719677d83b42780aae565b814b161 1 parent d13767d
@basvandijk basvandijk authored
Showing with 10 additions and 0 deletions.
  1. +10 −0 Data/Csv/Conversion.hs
View
10 Data/Csv/Conversion.hs
@@ -368,6 +368,16 @@ class FromField a where
class ToField a where
toField :: a -> Field
+instance FromField a => FromField (Maybe a) where
+ parseField s
+ | B.null s = pure Nothing
+ | otherwise = Just <$> parseField s
+ {-# INLINE parseField #-}
+
+instance ToField a => ToField (Maybe a) where
+ toField = maybe B.empty toField
+ {-# INLINE toField #-}
+
instance FromField Char where
parseField s
| T.compareLength t 1 == EQ = pure (T.head t)
Please sign in to comment.
Something went wrong with that request. Please try again.