Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Rename byHeader functions to byName

  • Loading branch information...
commit 6f22b509a18a930ae36d130866ab65d1401bf054 1 parent 87a4daf
@tibbe authored
View
22 Data/Ceason.hs
@@ -5,16 +5,16 @@ module Data.Ceason
(
-- * Encoding and decoding
decode
- , decodeByHeader
+ , decodeByName
, encode
- , encodeByHeader
+ , encodeByName
-- ** Encoding and decoding options
-- $options
, DecodeOptions(..)
, defaultDecodeOptions
, decodeWith
- , decodeByHeaderWith
+ , decodeByNameWith
-- * Core CSV types
, Csv
@@ -93,19 +93,19 @@ decode = decodeWith defaultDecodeOptions
-- | Efficiently deserialize CSV records from a lazy 'L.ByteString'.
-- If this fails due to incomplete or invalid input, @'Left' msg@ is
--- returned. Equivalent to @'decodeByHeaderWith'
+-- returned. Equivalent to @'decodeByNameWith'
-- 'defaultDecodeOptions'@.
-decodeByHeader :: FromNamedRecord a => L.ByteString
+decodeByName :: FromNamedRecord a => L.ByteString
-> Either String (Header, Vector a)
-decodeByHeader = decodeByHeaderWith defaultDecodeOptions
-{-# INLINE decodeByHeader #-}
+decodeByName = decodeByNameWith defaultDecodeOptions
+{-# INLINE decodeByName #-}
------------------------------------------------------------------------
-- ** Encoding and decoding options
-- $options
--
--- The 'decodeWith' and 'decodeByHeaderWith' functions lets you
+-- The 'decodeWith' and 'decodeByNameWith' functions lets you
-- customize how the CSV data is parsed. These can be used to e.g.
-- parse tab-separated data.
@@ -133,10 +133,10 @@ idDecodeWith :: DecodeOptions -> L.ByteString
-> Either String (Vector (Vector B.ByteString))
idDecodeWith !opts = decodeWithP (csv opts) pure
--- | Like 'decodeByHeader', but lets you customize how the CSV data is
+-- | Like 'decodeByName', but lets you customize how the CSV data is
-- parsed.
-decodeByHeaderWith :: FromNamedRecord a => DecodeOptions -> L.ByteString
+decodeByNameWith :: FromNamedRecord a => DecodeOptions -> L.ByteString
-> Either String (Header, Vector a)
-decodeByHeaderWith !opts =
+decodeByNameWith !opts =
decodeWithP (csvWithHeader opts)
(\ (hdr, vs) -> (,) <$> pure hdr <*> (parse $ traverse parseNamedRecord vs))
View
6 Data/Ceason/Encode.hs
@@ -12,7 +12,7 @@
-- strings.
module Data.Ceason.Encode
( encode
- , encodeByHeader
+ , encodeByName
) where
import Blaze.ByteString.Builder
@@ -36,8 +36,8 @@ encode = toLazyByteString
. V.toList . toRecord)
. V.toList
-encodeByHeader :: ToNamedRecord a => Header -> V.Vector a -> L.ByteString
-encodeByHeader hdr v =
+encodeByName :: ToNamedRecord a => Header -> V.Vector a -> L.ByteString
+encodeByName hdr v =
toLazyByteString ((mconcat . intersperse (fromChar ',') $
map fromByteString $ V.toList hdr) <>
fromByteString "\r\n" <> records)
View
4 benchmarks/Benchmarks.hs
@@ -47,10 +47,10 @@ main = do
decodePresidents = decode
decodePresidentsN :: BL.ByteString -> Either String (Header, Vector President)
- decodePresidentsN = decodeByHeader
+ decodePresidentsN = decodeByName
idDecode :: BL.ByteString -> Either String (Vector (Vector B.ByteString))
idDecode = decode
idDecodeN :: BL.ByteString -> Either String (Header, Vector (BSHashMap B.ByteString))
- idDecodeN = decodeByHeader
+ idDecodeN = decodeByName
View
4 tests/UnitTests.hs
@@ -40,12 +40,12 @@ encodesAs input expected =
namedEncodesAs :: [B.ByteString] -> [[(B.ByteString, B.ByteString)]]
-> BL.ByteString -> Assertion
namedEncodesAs hdr input expected =
- encodeByHeader (V.fromList hdr)
+ encodeByName (V.fromList hdr)
(V.fromList $ map (BSHashMap . HM.fromList) input) @?= expected
namedDecodesAs :: BL.ByteString -> [B.ByteString]
-> [[(B.ByteString, B.ByteString)]] -> Assertion
-namedDecodesAs input ehdr expected = case decodeByHeader input of
+namedDecodesAs input ehdr expected = case decodeByName input of
Right r -> (V.fromList ehdr, expected') @=? r
Left err -> assertFailure $
" input: " ++ show (BL8.unpack input) ++ "\n" ++
Please sign in to comment.
Something went wrong with that request. Please try again.