packages feed

javelin-io 0.1.1.0 → 0.1.1.1

raw patch · 6 files changed

+26/−187 lines, 6 filesdep ~basePVP ok

version bump matches the API change (PVP)

Dependency ranges changed: base

API changes (from Hackage documentation)

Files

CHANGELOG.md view
@@ -1,5 +1,9 @@ # Revision history for javelin-io +## Release 0.1.1.1++* Documentation fixes+ ## Release 0.1.1.0  * This is the first version of `javelin-io`.
javelin-io.cabal view
@@ -1,6 +1,6 @@ cabal-version:      3.0 name:               javelin-io-version:            0.1.1.0+version:            0.1.1.1 synopsis:           IO operations for the `javelin` package license:            MIT license-file:       LICENSE@@ -10,9 +10,9 @@ build-type:         Simple extra-doc-files:    CHANGELOG.md extra-source-files: test/data/*.csv-tested-with:        GHC ==9.8.1 -                     || ==9.6.3-                     || ==9.4.7+tested-with:        GHC ==9.8.2 +                     || ==9.6.4+                     || ==9.4.8 description:                  This package implements serialization/deserialization of 'Series', labeled one-dimensional arrays@@ -46,7 +46,7 @@                       Data.Series.Generic.IO                       Data.Series.Unboxed.IO     build-depends:    base >=4.15.0.0 && <4.20,-                      bytestring ^>=0.12,+                      bytestring >=0.11 && <0.13,                       cassava ^>=0.5,                       containers >=0.6 && <0.8,                       unordered-containers ^>=0.2,
src/Data/Series/Generic/IO.hs view
@@ -92,7 +92,7 @@ main :: IO () main = do     stream <- (...) -- Read the bytestring from somewhere-    let (latlongs  :: 'Series' Vector City LatLong) = either (error . show) id \<$\> `readCSV` stream+    let (latlongs  :: 'Series' Vector City LatLong) = either error id (`readCSV` stream)     print latlongs @ -}@@ -127,12 +127,11 @@ @ import "Data.Series.Generic" import "Data.Series.Generic.IO"-import "Data.Vector" +import "Data.Vector"  main :: IO () main = do-    stream <- (...) -- Read the bytestring from somewhere-    let (latlongs  :: 'Series' Vector City LatLong) = either (error . show) id \<$\> `readCSV` stream+    let (latlongs  :: 'Series' Vector City LatLong) = either error id \<$\> `readCSVFromFile` "somefile.csv"     print latlongs @ -}@@ -142,60 +141,7 @@ readCSVFromFile fp = fromFile fp readCSV   --{-|-Read a comma-separated value (CSV) bytestream into a series.--Consider the following bytestream read from a file:--@-latitude,longitude,city-48.856667,2.352222,Paris-40.712778,-74.006111,New York City-25.0375,121.5625,Taipei--34.603333,-58.381667,Buenos Aires-@--We want to get a series of the latitude an longitude, indexed by the column "city". First, we need-to do is to create a datatype representing the latitude and longitude information, and our index:--@-data LatLong = MkLatLong { latitude  :: Double-                         , longitude :: Double-                         }-    deriving ( Show )--newtype City = MkCity String-    deriving ( Eq, Ord, Show )-@--Second, we need to create an instance of `Data.Csv.FromNamedRecord` for our new types:--@-import "Data.Csv" ( 'FromNamedRecord', '(.:)' )--instance 'FromNamedRecord' LatLong where-    'parseNamedRecord' r = MkLatLong \<$\> r .: "latitude"-                                   \<*\> r .: "longitude"---instance 'FromNamedRecord' City where-    'parseNamedRecord' r = MkCity \<$\> r .: "city"-@--Finally, we're ready to read our stream:--@-import Data.Series-import Data.Series.IO--main :: IO ()-main = do-    stream <- (...) -- Read the bytestring from somewhere-    let (latlongs  :: 'Series' City LatLong) = either (error . show) id \<$\> `readCSV` stream-    print latlongs-@--}+-- | Serialize a 'Series' to bytes.  writeCSV :: (Vector v a, ToNamedRecord k, ToNamedRecord a)          => Series v k a          -> BL.ByteString@@ -205,8 +151,7 @@     pure $ CSV.encodeByName header $ NE.toList recs  --- | This is a helper function to write a 'Series' directly to CSV.--- See the documentation for 'writeCSV' on how to prepare your types.+-- | This is a helper function to write a 'Series' directly to a file. writeCSVToFile :: (MonadIO m, Vector v a, ToNamedRecord k, ToNamedRecord a)                => FilePath                -> Series v k a
src/Data/Series/IO.hs view
@@ -77,8 +77,8 @@  main :: IO () main = do-    let fp = "path/to/my/file.csv"-    let (latlongs  :: 'Series' City LatLong) = either (error . show) id \<$\> `readCSVFromFile` fp+    stream <- (...) -- get the bytes from somewhere+    let (latlongs  :: 'Series' City LatLong) = either error id (`readCSV` stream)     print latlongs @ -}@@ -99,8 +99,7 @@  main :: IO () main = do-    let fp = "path/to/my/file.csv"-    let (latlongs  :: 'Series' City LatLong) = either (error . show) id \<$\> `readCSVFromFile` fp+    let (latlongs  :: 'Series' City LatLong) = either error id \<$\> `readCSVFromFile` "somefile.csv"     print latlongs @ -}@@ -110,68 +109,14 @@ readCSVFromFile = Generic.IO.readCSVFromFile  --{-|-Read a comma-separated value (CSV) bytestream into a series.--Consider the following bytestream read from a file:--@-latitude,longitude,city-48.856667,2.352222,Paris-40.712778,-74.006111,New York City-25.0375,121.5625,Taipei--34.603333,-58.381667,Buenos Aires-@--We want to get a series of the latitude an longitude, indexed by the column "city". First, we need-to do is to create a datatype representing the latitude and longitude information, and our index:--@-data LatLong = MkLatLong { latitude  :: Double-                         , longitude :: Double-                         }-    deriving ( Show )--newtype City = MkCity String-    deriving ( Eq, Ord, Show )-@--Second, we need to create an instance of `Data.Csv.FromNamedRecord` for our new types:--@-import "Data.Csv" ( 'FromNamedRecord', '(.:)' )--instance 'FromNamedRecord' LatLong where-    'parseNamedRecord' r = MkLatLong \<$\> r .: "latitude"-                                   \<*\> r .: "longitude"---instance 'FromNamedRecord' City where-    'parseNamedRecord' r = MkCity \<$\> r .: "city"-@--Finally, we're ready to read our stream:--@-import Data.Series-import Data.Series.IO--main :: IO ()-main = do-    stream <- (...) -- Read the bytestring from somewhere-    let (latlongs  :: 'Series' City LatLong) = either (error . show) id \<$\> `readCSV` stream-    print latlongs-@--}+-- | Serialize a 'Series' to bytes.  writeCSV :: (ToNamedRecord k, ToNamedRecord a)          => Series k a          -> BL.ByteString writeCSV = Generic.IO.writeCSV  --- | This is a helper function to write a 'Series' directly to CSV.--- See the documentation for 'writeCSV' on how to prepare your types.+-- | This is a helper function to write a 'Series' directly to a file. writeCSVToFile :: (MonadIO m, ToNamedRecord k, ToNamedRecord a)                => FilePath                -> Series k a
src/Data/Series/Unboxed/IO.hs view
@@ -98,7 +98,7 @@ main :: IO () main = do     stream <- (...) -- Read the bytestring from somewhere-    let (latitudes  :: 'Series' City Latitude) = either (error . show) id \<$\> `readCSV` stream+    let (latitudes  :: 'Series' City Latitude) = either error id (`readCSV` stream)     print latitudes @ -}@@ -119,8 +119,7 @@  main :: IO () main = do-    stream <- (...) -- Read the bytestring from somewhere-    let (latitudes  :: 'Series' City Latitude) = either (error . show) id \<$\> `readCSV` stream+    let (latlongs  :: 'Series' City LatLong) = either error id \<$\> `readCSVFromFile` "somefile.csv"     print latitudes @ -}@@ -130,68 +129,14 @@ readCSVFromFile = Generic.IO.readCSVFromFile  --{-|-Read a comma-separated value (CSV) bytestream into a series.--Consider the following bytestream read from a file:--@-latitude,longitude,city-48.856667,2.352222,Paris-40.712778,-74.006111,New York City-25.0375,121.5625,Taipei--34.603333,-58.381667,Buenos Aires-@--We want to get a series of the latitude an longitude, indexed by the column "city". First, we need-to do is to create a datatype representing the latitude and longitude information, and our index:--@-data LatLong = MkLatLong { latitude  :: Double-                         , longitude :: Double-                         }-    deriving ( Show )--newtype City = MkCity String-    deriving ( Eq, Ord, Show )-@--Second, we need to create an instance of `Data.Csv.FromNamedRecord` for our new types:--@-import "Data.Csv" ( 'FromNamedRecord', '(.:)' )--instance 'FromNamedRecord' LatLong where-    'parseNamedRecord' r = MkLatLong \<$\> r .: "latitude"-                                   \<*\> r .: "longitude"---instance 'FromNamedRecord' City where-    'parseNamedRecord' r = MkCity \<$\> r .: "city"-@--Finally, we're ready to read our stream:--@-import Data.Series-import Data.Series.IO--main :: IO ()-main = do-    stream <- (...) -- Read the bytestring from somewhere-    let (latlongs  :: 'Series' City LatLong) = either (error . show) id \<$\> `readCSV` stream-    print latlongs-@--}+-- | Serialize a 'Series' to bytes.  writeCSV :: (ToNamedRecord k, ToNamedRecord a, Unbox a)          => Series k a          -> BL.ByteString writeCSV = Generic.IO.writeCSV  --- | This is a helper function to write a 'Series' directly to CSV.--- See the documentation for 'writeCSV' on how to prepare your types.+-- | This is a helper function to write a 'Series' directly to a file. writeCSVToFile :: (MonadIO m, ToNamedRecord k, ToNamedRecord a, Unbox a)                => FilePath                -> Series k a
test/Test/Data/Series/IO.hs view
@@ -43,7 +43,7 @@  testReadCSVFromFile :: TestTree testReadCSVFromFile = testCase "Read CSV data" $ do-    (latlongs  :: Series Vector City LatLong) <- either (error . show) id <$> readCSVFromFile "test/data/lat-long-city.csv"+    (latlongs  :: Series Vector City LatLong) <- either error id <$> readCSVFromFile "test/data/lat-long-city.csv"      let latitudes  = fmap lat latlongs         longitudes = fmap long latlongs@@ -63,11 +63,11 @@  testWriteCSVToFile :: TestTree testWriteCSVToFile = testCase "Write CSV data" $ do-    (latlongs  :: Series Vector City LatLong) <- either (error . show) id <$> readCSVFromFile "test/data/lat-long-city.csv"+    (latlongs  :: Series Vector City LatLong) <- either error id <$> readCSVFromFile "test/data/lat-long-city.csv"          (written :: Series Vector City LatLong) <- withSystemTempDirectory "test-javelin-op" $ \dirname -> do         writeCSVToFile (dirname </> "myseries.csv") latlongs -        either (error . show) id <$> readCSVFromFile (dirname </> "myseries.csv")+        either error id <$> readCSVFromFile (dirname </> "myseries.csv")          assertEqual mempty latlongs written