Permalink
Browse files

Add FromField instance for ()

  • Loading branch information...
1 parent 7db8f74 commit ebd1bd466cdbba452a6be469a2a33b1a2527a019 @Shimuuar Shimuuar committed Jan 2, 2013
Showing with 14 additions and 1 deletion.
  1. +9 −1 Data/Csv.hs
  2. +5 −0 Data/Csv/Conversion.hs
View
@@ -143,7 +143,15 @@ import Data.Csv.Types
-- > Left err -> putStrLn err
-- > Right v -> forM_ v $ \ (Hex val1, Hex val2) ->
-- > print (val1, val2)
-
+--
+-- In order to ignore column you can use unit type '()'. It always
+-- successfully decode. Note that it lacks corresponding 'ToField'
+-- instance. It serves as placeholder to indicate that there's
+-- something in the column you don't care what.
+--
+-- > case decode False "foo,1\r\nbar,22" of
+-- > Left err -> putStrLn err
+-- > Right v -> forM_ v $ \ ((), i) -> print (i :: Int)
-- $encoding
--
@@ -386,6 +386,11 @@ instance ToField a => ToField (Maybe a) where
toField = maybe B.empty toField
{-# INLINE toField #-}
+-- | Could used to ignore column during decoding.
+instance FromField () where
+ parseField _ = pure ()
+ {-# INLINE parseField #-}
+
-- | Assumes UTF-8 encoding.
instance FromField Char where
parseField s

0 comments on commit ebd1bd4

Please sign in to comment.