~jaro/balkon

58f69b24f9a2138833dd86fbc8a1590760fecf64 — Jaro 11 months ago 4ff2ea2
Add helper function for run-length encoding.
2 files changed, 9 insertions(+), 0 deletions(-)

M balkon.cabal
A test/Data/Text/ParagraphLayout/RunLengthEncoding.hs
M balkon.cabal => balkon.cabal +1 -0
@@ 197,6 197,7 @@ test-suite balkon-test
        Data.Text.ParagraphLayout.RectSpec,
        Data.Text.ParagraphLayout.Rich.ParagraphData,
        Data.Text.ParagraphLayout.RichSpec,
        Data.Text.ParagraphLayout.RunLengthEncoding,
        Data.Text.ParagraphLayout.TextData

    -- Test dependencies.

A test/Data/Text/ParagraphLayout/RunLengthEncoding.hs => test/Data/Text/ParagraphLayout/RunLengthEncoding.hs +8 -0
@@ 0,0 1,8 @@
module Data.Text.ParagraphLayout.RunLengthEncoding (runLengthDecode) where

-- | Decode a run-length encoded list.
--
-- Helpful for concisely representing lists with many repeated values.
runLengthDecode :: [(Int, a)] -> [a]
runLengthDecode [] = []
runLengthDecode ((len, val) : xs) = replicate len val ++ runLengthDecode xs