From 58f69b24f9a2138833dd86fbc8a1590760fecf64 Mon Sep 17 00:00:00 2001 From: Jaro Date: Sun, 21 May 2023 21:03:55 +0200 Subject: [PATCH] Add helper function for run-length encoding. --- balkon.cabal | 1 + test/Data/Text/ParagraphLayout/RunLengthEncoding.hs | 8 ++++++++ 2 files changed, 9 insertions(+) create mode 100644 test/Data/Text/ParagraphLayout/RunLengthEncoding.hs diff --git a/balkon.cabal b/balkon.cabal index 899dc95..bb75ba2 100644 --- a/balkon.cabal +++ b/balkon.cabal @@ -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. diff --git a/test/Data/Text/ParagraphLayout/RunLengthEncoding.hs b/test/Data/Text/ParagraphLayout/RunLengthEncoding.hs new file mode 100644 index 0000000..ddffd04 --- /dev/null +++ b/test/Data/Text/ParagraphLayout/RunLengthEncoding.hs @@ -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 -- 2.30.2