Sparkline in unicode: Difference between revisions

m
some code cleanup
m (added type signature for parseWithSeps)
m (some code cleanup)
Line 135:
<lang haskell>
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]
Line 155 ⟶ 146:
 
makeSparkLine :: String -> (String, Stats)
makeSparkLine xs = (sptoSparkLine parsed, stats pparsed)
where parsed = map read $ filter (not . null) $ splitOneOf " ," xs
where sp = toSparkLine p
p = parseWithSeps " ," xs
data Stats = Stats { minValue, maxValue, rangeOfValues :: Double,
Anonymous user