Skip to content

Commit

Permalink
Add FromField instance for ()
Browse files Browse the repository at this point in the history
  • Loading branch information
Shimuuar committed Jan 2, 2013
1 parent 7db8f74 commit ebd1bd4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
10 changes: 9 additions & 1 deletion Data/Csv.hs
Expand Up @@ -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
--
Expand Down
5 changes: 5 additions & 0 deletions Data/Csv/Conversion.hs
Expand Up @@ -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
Expand Down

0 comments on commit ebd1bd4

Please sign in to comment.