Sparkline in unicode: Difference between revisions

Content added Content deleted
m (added type signature for parseWithSeps)
m (some code cleanup)
Line 135: Line 135:
<lang haskell>
<lang haskell>
import Data.Char (chr)
import Data.Char (chr)
import Data.List.Split (splitOneOf)

parseWithSeps :: Read a => String -> String -> [a]
parseWithSeps _ [] = []
parseWithSeps sep xs =
if null yes
then parseWithSeps sep (tail rest)
else read yes : parseWithSeps sep rest
where
yes = takeWhile (`notElem` sep) xs
(_, rest) = splitAt (length yes) xs


toSparkLine :: [Double] -> [Char]
toSparkLine :: [Double] -> [Char]
Line 155: Line 146:


makeSparkLine :: String -> (String, Stats)
makeSparkLine :: String -> (String, Stats)
makeSparkLine xs = (sp, stats p)
makeSparkLine xs = (toSparkLine parsed, stats parsed)
where parsed = map read $ filter (not . null) $ splitOneOf " ," xs
where sp = toSparkLine p
p = parseWithSeps " ," xs
data Stats = Stats { minValue, maxValue, rangeOfValues :: Double,
data Stats = Stats { minValue, maxValue, rangeOfValues :: Double,