{-|
Module      : TimeSeries.Utils
Copyright   : (C) 2013 Parallel Scientific Labs, LLC
License     : GPL-2
Stability   : experimental
Portability : portable

Utilities.

-}
module TimeSeries.Utils where

-- | Separate given string by comma.
--
-- >>> comma "foo,bar,buzz"
-- ["foo","bar","buzz"]
--
comma :: String -> [String]
comma str = case break (== ',') str of
  ([],  post) -> [post]
  (pre, post) | null post -> [pre]
              | otherwise -> pre : comma (tail post)

-- | Format contents of CSV file.
--
-- See \"data/correlated-walks_rho09_n100000_k5.csv\" for input sample.
--
formatCSV :: String -> [[Double]]
formatCSV = map (map read . tail . comma) . tail . lines