module Data.Table (
Tabulatable(..)
, labels1
, tabulation1
, labels2
, tabulation2
, labels3
, tabulation3
) where
import Codec.Compression.GZip (compress, decompress)
import Control.Monad (ap)
import Data.List (intercalate, transpose)
import Data.List.Split (splitOn)
import qualified Data.ByteString.Lazy.Char8 as BS (pack, readFile, unpack, writeFile)
class Tabulatable a where
labels :: a -> [String]
tabulation :: a -> [String]
tabulations :: [a] -> [[String]]
tabulations = ap ((:) . labels . head) (map tabulation)
tabulationsT :: [a] -> [[String]]
tabulationsT = transpose . tabulations
tabulations' :: [a] -> String
tabulations' = unlines . map (intercalate "\t") . tabulations
tabulationsT' :: [a] -> String
tabulationsT' = unlines . map (intercalate "\t") . tabulationsT
untabulation :: [String] -> a
untabulations :: [[String]] -> [a]
untabulations = map untabulation . tail
untabulations' :: String -> [a]
untabulations' = untabulations . map (splitOn "\t") . lines
sorted :: [a] -> [a]
sorted = undefined
find :: a -> [a] -> Maybe a
find = undefined
readUncompressed :: FilePath -> IO [a]
readUncompressed = fmap untabulations' . readFile
readCompressed :: FilePath -> IO [a]
readCompressed = fmap (untabulations' . BS.unpack . decompress) . BS.readFile
writeUncompressed :: FilePath -> [a] -> IO ()
writeUncompressed = (. tabulations') . writeFile
writeCompressed :: FilePath -> [a] -> IO ()
writeCompressed = (. compress . BS.pack . tabulations') . BS.writeFile
labels1 :: Tabulatable a
=> String
-> a
-> [String]
labels1 s x = labels x ++ [s]
labels2 :: (Tabulatable a, Tabulatable b)
=> String
-> a
-> b
-> [String]
labels2 s x y = concat [labels x, labels y, [s]]
labels3 :: (Tabulatable a, Tabulatable b, Tabulatable c)
=> String
-> a
-> b
-> c
-> [String]
labels3 s x y z = concat [labels x, labels y, labels z, [s]]
tabulation1 :: (Tabulatable a, Show e)
=> a
-> e
-> [String]
tabulation1 x s = tabulation x ++ [show s]
tabulation2 :: (Tabulatable a, Tabulatable b, Show e)
=> a
-> b
-> e
-> [String]
tabulation2 x y s = concat [tabulation x, tabulation y, [show s]]
tabulation3 :: (Tabulatable a, Tabulatable b, Tabulatable c, Show e)
=> a
-> b
-> c
-> e
-> [String]
tabulation3 x y z s = concat [tabulation x, tabulation y, tabulation z, [show s]]