Skip to content
Snippets Groups Projects
Commit 63f82c9f authored by Alice Brenon's avatar Alice Brenon
Browse files

Factorise and expose TSV option decoder to client code

parent 5c766a5a
No related branches found
No related tags found
No related merge requests found
{-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE ScopedTypeVariables #-}
module GEODE.Metadata.TSV module GEODE.Metadata.TSV
( readNamedTsv ( fromTsv
, readNamedTsv
, readTsv , readTsv
, toTsv , toTsv
, tsvFile , tsvFile
...@@ -15,16 +16,15 @@ import Data.Foldable (toList) ...@@ -15,16 +16,15 @@ import Data.Foldable (toList)
import Data.Vector (Vector) import Data.Vector (Vector)
import GEODE.Metadata.TSV.Header (HasDefaultHeader, getHeader, for) import GEODE.Metadata.TSV.Header (HasDefaultHeader, getHeader, for)
fromTsv :: DecodeOptions
fromTsv = DecodeOptions {decDelimiter = fromIntegral (fromEnum '\t')}
readNamedTsv :: FromNamedRecord a => FilePath -> IO (Either String (Vector a)) readNamedTsv :: FromNamedRecord a => FilePath -> IO (Either String (Vector a))
readNamedTsv source = readNamedTsv source =
(fmap snd . decodeByNameWith fromTsv) <$> ByteString.readFile source (fmap snd . decodeByNameWith fromTsv) <$> ByteString.readFile source
where
fromTsv = DecodeOptions {decDelimiter = fromIntegral (fromEnum '\t')}
readTsv :: FromRecord a => FilePath -> IO (Either String (Vector a)) readTsv :: FromRecord a => FilePath -> IO (Either String (Vector a))
readTsv source = decodeWith fromTsv NoHeader <$> ByteString.readFile source readTsv source = decodeWith fromTsv NoHeader <$> ByteString.readFile source
where
fromTsv = DecodeOptions {decDelimiter = fromIntegral (fromEnum '\t')}
toTsv :: EncodeOptions toTsv :: EncodeOptions
toTsv = defaultEncodeOptions toTsv = defaultEncodeOptions
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment