~jaro/balkon

ref: 3e3fef4440b5d982144bdb4b13a3d784ba686233 balkon/src/Data/Text/ParagraphLayout/Internal/LineNumbers.hs -rw-r--r-- 680 bytes
3e3fef44Jaro Add content rect to Fragment. 1 year, 2 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
module Data.Text.ParagraphLayout.Internal.LineNumbers
    ( LineNumbers
    , lineNumbers
    , lineNumbersWithDuplication
    )
where

import qualified Data.List.NonEmpty as NonEmpty

-- | Data types that contain numbered lines.
class LineNumbers ml where

    -- | A list of all line numbers in ascending order,
    -- with possible duplicates.
    lineNumbersWithDuplication :: ml -> [Int]

-- | A list of all unique line numbers, in ascending order.
lineNumbers :: (LineNumbers ml) => ml -> [Int]
lineNumbers ml = dedupe $ lineNumbersWithDuplication ml

-- | Remove duplicates from a sorted list.
dedupe :: Eq a => [a] -> [a]
dedupe xs = map NonEmpty.head $ NonEmpty.group xs